simpleOAuthClientProvider.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.InMemoryOAuthClientProvider = void 0;
  4. /**
  5. * In-memory OAuth client provider for demonstration purposes
  6. * In production, you should persist tokens securely
  7. */
  8. class InMemoryOAuthClientProvider {
  9. constructor(_redirectUrl, _clientMetadata, onRedirect, clientMetadataUrl) {
  10. this._redirectUrl = _redirectUrl;
  11. this._clientMetadata = _clientMetadata;
  12. this.clientMetadataUrl = clientMetadataUrl;
  13. this._onRedirect =
  14. onRedirect ||
  15. (url => {
  16. console.log(`Redirect to: ${url.toString()}`);
  17. });
  18. }
  19. get redirectUrl() {
  20. return this._redirectUrl;
  21. }
  22. get clientMetadata() {
  23. return this._clientMetadata;
  24. }
  25. clientInformation() {
  26. return this._clientInformation;
  27. }
  28. saveClientInformation(clientInformation) {
  29. this._clientInformation = clientInformation;
  30. }
  31. tokens() {
  32. return this._tokens;
  33. }
  34. saveTokens(tokens) {
  35. this._tokens = tokens;
  36. }
  37. redirectToAuthorization(authorizationUrl) {
  38. this._onRedirect(authorizationUrl);
  39. }
  40. saveCodeVerifier(codeVerifier) {
  41. this._codeVerifier = codeVerifier;
  42. }
  43. codeVerifier() {
  44. if (!this._codeVerifier) {
  45. throw new Error('No code verifier saved');
  46. }
  47. return this._codeVerifier;
  48. }
  49. }
  50. exports.InMemoryOAuthClientProvider = InMemoryOAuthClientProvider;
  51. //# sourceMappingURL=simpleOAuthClientProvider.js.map