Skip to content

Commit

Permalink
new flat for tryLogin to disable oauth2-style state check
Browse files Browse the repository at this point in the history
  • Loading branch information
manfredsteyer committed Aug 28, 2017
1 parent 0e386a7 commit 91fa005
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
17 changes: 6 additions & 11 deletions angular-oauth2-oidc/src/oauth-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,8 @@ export class OAuthService {
return Promise.reject('Either requestAccessToken or oidc or both must be true.');
}

if (this.requestAccessToken && (!accessToken || !state)) return Promise.resolve();
if (this.requestAccessToken && !accessToken) return Promise.resolve();
if (this.requestAccessToken && !options.disableOAuth2StateCheck && !state) return Promise.resolve();
if (this.oidc && !idToken) return Promise.resolve();

var stateParts = state.split(';');
Expand All @@ -905,22 +906,16 @@ export class OAuthService {
var nonceInState = stateParts[0];


// Our state might be URL encoded
// Check for this and then decode it if it is
// TODO: Check this!
/*
let decodedState = decodeURIComponent(state);
if (decodedState != state) {
state = decodedState;
}
*/
if (this.requestAccessToken) {
if (this.requestAccessToken && !options.disableOAuth2StateCheck) {
let success = this.validateNonceForAccessToken(accessToken, nonceInState);
if (!success) {
let event = new OAuthErrorEvent('invalid_nonce_in_state', null);
this.eventsSubject.next(event);
return Promise.reject(event);
}
}

if (this.requestAccessToken) {
this.storeAccessTokenResponse(accessToken, null, parts['expires_in']);
}

Expand Down
2 changes: 1 addition & 1 deletion angular-oauth2-oidc/src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-oauth2-oidc",
"version": "2.0.11",
"version": "2.0.12",
"repository": {
"type": "git",
"url": "https://github.com/manfredsteyer/angular-oauth2-oidc"
Expand Down
10 changes: 10 additions & 0 deletions angular-oauth2-oidc/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ export class LoginOptions {
* pass the iframes hash fragment to this method.
*/
customHashFragment?: string;

/**
* Set this to true to disable the oauth2 state
* check which is a best practice to avoid
* security attacks.
* As OIDC defines a nonce check that includes
* this, this can be set to true when only doing
* OIDC.
*/
disableOAuth2StateCheck?: boolean;
}

/**
Expand Down

0 comments on commit 91fa005

Please sign in to comment.