From 74b703655e62fd872c4559aea010cdf53f97b9ac Mon Sep 17 00:00:00 2001 From: Cristian Nitescu Date: Fri, 4 Jun 2021 11:22:07 +0200 Subject: [PATCH] allow non standard providers --- src/AuthService.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/AuthService.ts b/src/AuthService.ts index 8b0f273..b9c0c68 100644 --- a/src/AuthService.ts +++ b/src/AuthService.ts @@ -10,6 +10,8 @@ export interface AuthServiceProps { contentType?: string location: Location provider: string + authorizeEndpoint: string + tokenEndpoint: string redirectUri?: string scopes: string[] autoRefresh?: boolean @@ -156,7 +158,7 @@ export class AuthService { // this will do a full page reload and to to the OAuth2 provider's login page and then redirect back to redirectUri authorize(): boolean { - const { clientId, provider, redirectUri, scopes } = this.props + const { clientId, provider, authorizeEndpoint, redirectUri, scopes } = this.props const pkce = createPKCECodes() window.localStorage.setItem('pkce', JSON.stringify(pkce)) @@ -173,7 +175,7 @@ export class AuthService { codeChallengeMethod: 'S256' } // Responds with a 302 redirect - const url = `${provider}/authorize?${toUrlEncoded(query)}` + const url = `${authorizeEndpoint || `${provider}/authorize`}?${toUrlEncoded(query)}` window.location.replace(url) return true } @@ -185,6 +187,7 @@ export class AuthService { clientSecret, contentType, provider, + tokenEndpoint, redirectUri, autoRefresh = true } = this.props @@ -212,7 +215,7 @@ export class AuthService { } } - const response = await fetch(`${provider}/token`, { + const response = await fetch(`${tokenEndpoint || `${provider}/token`}`, { headers: { 'Content-Type': contentType || 'application/x-www-form-urlencoded' },