simpleOAuthClientProvider.js 1.4 KB

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