Skip to content

Commit 91fa005

Browse files
committed
new flat for tryLogin to disable oauth2-style state check
1 parent 0e386a7 commit 91fa005

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

angular-oauth2-oidc/src/oauth-service.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,8 @@ export class OAuthService {
895895
return Promise.reject('Either requestAccessToken or oidc or both must be true.');
896896
}
897897

898-
if (this.requestAccessToken && (!accessToken || !state)) return Promise.resolve();
898+
if (this.requestAccessToken && !accessToken) return Promise.resolve();
899+
if (this.requestAccessToken && !options.disableOAuth2StateCheck && !state) return Promise.resolve();
899900
if (this.oidc && !idToken) return Promise.resolve();
900901

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

907908

908-
// Our state might be URL encoded
909-
// Check for this and then decode it if it is
910-
// TODO: Check this!
911-
/*
912-
let decodedState = decodeURIComponent(state);
913-
if (decodedState != state) {
914-
state = decodedState;
915-
}
916-
*/
917-
if (this.requestAccessToken) {
909+
if (this.requestAccessToken && !options.disableOAuth2StateCheck) {
918910
let success = this.validateNonceForAccessToken(accessToken, nonceInState);
919911
if (!success) {
920912
let event = new OAuthErrorEvent('invalid_nonce_in_state', null);
921913
this.eventsSubject.next(event);
922914
return Promise.reject(event);
923915
}
916+
}
917+
918+
if (this.requestAccessToken) {
924919
this.storeAccessTokenResponse(accessToken, null, parts['expires_in']);
925920
}
926921

angular-oauth2-oidc/src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-oauth2-oidc",
3-
"version": "2.0.11",
3+
"version": "2.0.12",
44
"repository": {
55
"type": "git",
66
"url": "https://github.com/manfredsteyer/angular-oauth2-oidc"

angular-oauth2-oidc/src/types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ export class LoginOptions {
3131
* pass the iframes hash fragment to this method.
3232
*/
3333
customHashFragment?: string;
34+
35+
/**
36+
* Set this to true to disable the oauth2 state
37+
* check which is a best practice to avoid
38+
* security attacks.
39+
* As OIDC defines a nonce check that includes
40+
* this, this can be set to true when only doing
41+
* OIDC.
42+
*/
43+
disableOAuth2StateCheck?: boolean;
3444
}
3545

3646
/**

0 commit comments

Comments
 (0)