diff --git a/README.md b/README.md index 2c735094..a2595769 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +# Archiving this repository: Original angular-oauth2-oidc now does codeflow. Will request to add contextual parameters. + # angular-oauth2-oidc-codeflow [![Build Status](https://travis-ci.org/bechhansen/angular-oauth2-oidc.svg?branch=master)](https://travis-ci.org/bechhansen/angular-oauth2-oidc) diff --git a/projects/lib/src/oauth-service.ts b/projects/lib/src/oauth-service.ts index 64a765c4..6e4cd15a 100644 --- a/projects/lib/src/oauth-service.ts +++ b/projects/lib/src/oauth-service.ts @@ -668,6 +668,8 @@ export class OAuthService extends AuthConfig { tokenResponse.scope ); + this.storeAdditionalParameters(tokenResponse); + this.eventsSubject.next(new OAuthSuccessEvent('token_received')); resolve(tokenResponse); }, @@ -737,6 +739,8 @@ export class OAuthService extends AuthConfig { this.debug('refresh tokenResponse', tokenResponse); this.storeAccessTokenResponse(tokenResponse.access_token, tokenResponse.refresh_token, tokenResponse.expires_in, tokenResponse.scope); + this.storeAdditionalParameters(tokenResponse); + if (this.oidc && tokenResponse.id_token) { this.processIdToken(tokenResponse.id_token, tokenResponse.access_token). then(result => { @@ -1302,6 +1306,23 @@ export class OAuthService extends AuthConfig { } } + /** + * Store additional parameters received in the tokenResponse + * @param tokenResponse the parameters from the token post request + */ + private storeAdditionalParameters(tokenResponse) { + const additionalParams = JSON.parse(this._storage.getItem('additional_params')) || {}; + + const tokenKeys = ['access_token', 'refresh_token', 'expires_in', 'scope']; + Object.keys(tokenResponse).forEach(key => { + if (!tokenKeys.includes(key)) { // don't store parameters related to token, stored elsewhere + additionalParams[key] = tokenResponse[key]; + } + }); + + this._storage.setItem('additional_params', JSON.stringify(additionalParams)); + } + /** * Checks whether there are tokens in the hash fragment * as a result of the implicit flow. These tokens are @@ -1737,6 +1758,17 @@ export class OAuthService extends AuthConfig { return parseInt(this._storage.getItem('id_token_expires_at'), 10); } + /** + * Get additional parameters that have been saved after a log in + * @returns {object} key:value pairs of additional parameters from oAuth login + */ + public getAdditionalParameters(): object { + if (!this._storage.getItem('additional_params')) { + return null; + } + return JSON.parse(this._storage.getItem('additional_params')); + } + /** * Checkes, whether there is a valid access_token. */