From e4483140ca8b19b57aa498d9ca7449aa61652f01 Mon Sep 17 00:00:00 2001 From: Sebastian Gingter Date: Tue, 24 Sep 2019 09:20:51 +0200 Subject: [PATCH] Add support for hash location strategy in code flow --- projects/lib/src/oauth-service.ts | 35 ++++++++++++++++--------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/projects/lib/src/oauth-service.ts b/projects/lib/src/oauth-service.ts index 2b9de9dc..b568733c 100644 --- a/projects/lib/src/oauth-service.ts +++ b/projects/lib/src/oauth-service.ts @@ -1380,24 +1380,8 @@ export class OAuthService extends AuthConfig implements OnDestroy { } } - - private parseQueryString(queryString: string): object { - if (!queryString || queryString.length === 0) { - return {}; - } - - if (queryString.charAt(0) === '?') { - queryString = queryString.substr(1); - } - - return this.urlHelper.parseQueryString(queryString); - - - } - public tryLoginCodeFlow(): Promise { - - const parts = this.parseQueryString(window.location.search) + const parts = this.getCodePartsFromUrl(window.location.search); const code = parts['code']; const state = parts['state']; @@ -1445,6 +1429,23 @@ export class OAuthService extends AuthConfig implements OnDestroy { } } + /** + * Retrieve the returned auth code from the redirect uri that has been called. + * If required also check hash, as we could use hash location strategy. + */ + private getCodePartsFromUrl(queryString: string): object { + if (!queryString || queryString.length === 0) { + return this.urlHelper.getHashFragmentParams(); + } + + // normalize query string + if (queryString.charAt(0) === '?') { + queryString = queryString.substr(1); + } + + return this.urlHelper.parseQueryString(queryString); + } + /** * Get token using an intermediate code. Works for the Authorization Code flow. */