@@ -37,7 +37,6 @@ export class Authorization {
3737 public readonly products : ko . Observable < Product [ ] > ;
3838 public readonly selectedSubscriptionKey : ko . Observable < string > ;
3939 public readonly collapsedAuth : ko . Observable < boolean > ;
40-
4140
4241 constructor (
4342 private readonly sessionManager : SessionManager ,
@@ -74,7 +73,7 @@ export class Authorization {
7473 public consoleOperation : ko . Observable < ConsoleOperation > ;
7574
7675 @Param ( )
77- public headers : ko . ObservableArray < ConsoleHeader > ;
76+ public headers : ko . ObservableArray < ConsoleHeader > ;
7877
7978 @Param ( )
8079 public codeSample : ko . Observable < string > ;
@@ -151,14 +150,14 @@ export class Authorization {
151150 keyHeader . required = true ;
152151 keyHeader . value ( accessToken ) ;
153152
154- if ( ! this . isGraphQL ( ) ) {
153+ if ( ! this . isGraphQL ( ) ) {
155154 this . consoleOperation ( ) . request . headers . push ( keyHeader ) ;
156155 this . updateRequestSummary ( ) ;
157156 }
158157 else {
159158 this . headers . push ( keyHeader ) ;
160159 }
161-
160+
162161 this . authenticated ( true ) ;
163162 }
164163
@@ -195,7 +194,7 @@ export class Authorization {
195194 keyHeader . required = true ;
196195 keyHeader . value ( subscriptionKey ) ;
197196
198- if ( ! this . isGraphQL ( ) ) {
197+ if ( ! this . isGraphQL ( ) ) {
199198 this . consoleOperation ( ) . request . headers . push ( keyHeader ) ;
200199 this . updateRequestSummary ( ) ;
201200 }
@@ -230,7 +229,7 @@ export class Authorization {
230229 * Initiates specified authentication flow.
231230 * @param grantType OAuth grant type, e.g. "implicit" or "authorization_code".
232231 */
233- public async authenticateOAuth ( grantType : string ) : Promise < void > {
232+ public async authenticateOAuth ( grantType : string ) : Promise < void > {
234233 const api = this . api ( ) ;
235234 const authorizationServer = this . authorizationServer ( ) ;
236235 const scopeOverride = api . authenticationSettings ?. oAuth2 ?. scope ;
@@ -240,7 +239,12 @@ export class Authorization {
240239 authorizationServer . scopes = [ scopeOverride ] ;
241240 }
242241
243- const accessToken = await this . oauthService . authenticate ( grantType , authorizationServer ) ;
242+ const accessToken = await this . oauthService . authenticate ( grantType , authorizationServer , api . name ) ;
243+
244+ if ( ! accessToken ) {
245+ return ;
246+ }
247+
244248 await this . setStoredCredentials ( serverName , scopeOverride , grantType , accessToken ) ;
245249
246250 this . setAuthorizationHeader ( accessToken ) ;
@@ -276,15 +280,15 @@ export class Authorization {
276280 }
277281
278282 public removeHeader ( header : ConsoleHeader ) : void {
279- if ( ! this . isGraphQL ( ) ) {
283+ if ( ! this . isGraphQL ( ) ) {
280284 this . consoleOperation ( ) . request . headers . remove ( header ) ;
281285 this . updateRequestSummary ( ) ;
282286 }
283287 else {
284288 this . headers . remove ( header ) ;
285289 }
286290 }
287-
291+
288292 private async setStoredCredentials ( serverName : string , scopeOverride : string , grantType : string , accessToken : string ) : Promise < void > {
289293 const oauthSession = await this . sessionManager . getItem < OAuthSession > ( oauthSessionKey ) || { } ;
290294 const recordKey = this . getSessionRecordKey ( serverName , scopeOverride ) ;
@@ -324,7 +328,7 @@ export class Authorization {
324328 this . authorizationError ( "Oops, something went wrong. Try again later." ) ;
325329 }
326330 }
327-
331+
328332 private async loadSubscriptionKeys ( ) : Promise < void > {
329333 const userId = await this . usersService . getCurrentUserId ( ) ;
330334
@@ -381,8 +385,8 @@ export class Authorization {
381385 } else {
382386 this . setSubscriptionKeyHeader ( subscriptionKey ) ;
383387 }
384-
385- if ( ! this . isGraphQL ( ) ) {
388+
389+ if ( ! this . isGraphQL ( ) ) {
386390 this . updateRequestSummary ( ) ;
387391 }
388392 }
0 commit comments