@@ -39,19 +39,7 @@ export class AuthService {
3939 }
4040
4141 async startLoginRedirect ( ) : Promise < void > {
42- const state = this . createRandomUrlSafeString ( 32 ) ;
43- const verifier = this . createRandomUrlSafeString ( 64 ) ;
44- const challenge = await this . createPkceChallenge ( verifier ) ;
45-
46- const requestState : PkceAuthorizationRequestState = {
47- state,
48- verifier,
49- createdAtUtcMs : Date . now ( )
50- } ;
51-
52- sessionStorage . setItem ( PKCE_REQUEST_STORAGE_KEY , JSON . stringify ( requestState ) ) ;
53-
54- const authorizeUrl = this . createAuthorizeUrl ( state , challenge ) ;
42+ const authorizeUrl = await this . createAuthorizeRedirectUrl ( ) ;
5543 window . location . assign ( authorizeUrl ) ;
5644 }
5745
@@ -111,8 +99,9 @@ export class AuthService {
11199 window . location . assign ( logoutUrl ) ;
112100 }
113101
114- openRegisterPage ( ) : void {
115- const registerUrl = `${ this . appEnvironment . auth . authority . replace ( / \/ $ / , '' ) } /Identity/Account/Register` ;
102+ async openRegisterPage ( ) : Promise < void > {
103+ const authorizePath = await this . createAuthorizeRedirectPath ( ) ;
104+ const registerUrl = `${ this . appEnvironment . auth . authority . replace ( / \/ $ / , '' ) } /Identity/Account/Register?returnUrl=${ encodeURIComponent ( authorizePath ) } ` ;
116105 window . location . assign ( registerUrl ) ;
117106 }
118107
@@ -158,18 +147,47 @@ export class AuthService {
158147
159148 private createAuthorizeUrl ( state : string , challenge : string ) : string {
160149 const authorizeEndpoint = `${ this . appEnvironment . auth . authority . replace ( / \/ $ / , '' ) } /connect/authorize` ;
161- const scopes = this . appEnvironment . auth . scopes . join ( ' ' ) ;
162- const params = new URLSearchParams ( {
150+ const params = this . createAuthorizeParams ( state , challenge ) ;
151+
152+ return `${ authorizeEndpoint } ?${ params . toString ( ) } ` ;
153+ }
154+
155+ private async createAuthorizeRedirectUrl ( ) : Promise < string > {
156+ const { state, challenge } = await this . createPkceAuthorizationRequestState ( ) ;
157+ return this . createAuthorizeUrl ( state , challenge ) ;
158+ }
159+
160+ private async createAuthorizeRedirectPath ( ) : Promise < string > {
161+ const { state, challenge } = await this . createPkceAuthorizationRequestState ( ) ;
162+ const params = this . createAuthorizeParams ( state , challenge ) ;
163+ return `/connect/authorize?${ params . toString ( ) } ` ;
164+ }
165+
166+ private createAuthorizeParams ( state : string , challenge : string ) : URLSearchParams {
167+ return new URLSearchParams ( {
163168 response_type : this . appEnvironment . auth . responseType ,
164169 client_id : this . appEnvironment . auth . clientId ,
165170 redirect_uri : this . appEnvironment . auth . redirectUri ,
166- scope : scopes ,
171+ scope : this . appEnvironment . auth . scopes . join ( ' ' ) ,
167172 state,
168173 code_challenge : challenge ,
169174 code_challenge_method : 'S256'
170175 } ) ;
176+ }
171177
172- return `${ authorizeEndpoint } ?${ params . toString ( ) } ` ;
178+ private async createPkceAuthorizationRequestState ( ) : Promise < { state : string ; challenge : string } > {
179+ const state = this . createRandomUrlSafeString ( 32 ) ;
180+ const verifier = this . createRandomUrlSafeString ( 64 ) ;
181+ const challenge = await this . createPkceChallenge ( verifier ) ;
182+
183+ const requestState : PkceAuthorizationRequestState = {
184+ state,
185+ verifier,
186+ createdAtUtcMs : Date . now ( )
187+ } ;
188+
189+ sessionStorage . setItem ( PKCE_REQUEST_STORAGE_KEY , JSON . stringify ( requestState ) ) ;
190+ return { state, challenge } ;
173191 }
174192
175193 private createLogoutUrl ( idTokenHint ?: string ) : string {
0 commit comments