Skip to content

Commit

Permalink
Merge pull request #629 from jfyne/gh-628/createNonce
Browse files Browse the repository at this point in the history
Correct implementation of rfc7636 section 4.1
  • Loading branch information
manfredsteyer authored Mar 2, 2020
2 parents d49021a + 5b14963 commit be8d273
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions projects/lib/src/oauth-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -785,8 +785,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
tap(result => this.storeIdToken(result)),
map(_ => tokenResponse)
);
}
else {
} else {
return of(tokenResponse);
}
}))
Expand Down Expand Up @@ -1402,8 +1401,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
public tryLogin(options: LoginOptions = null): Promise<boolean> {
if (this.config.responseType === 'code') {
return this.tryLoginCodeFlow().then(_ => true);
}
else {
} else {
return this.tryLoginImplicitFlow(options);
}
}
Expand Down Expand Up @@ -2141,26 +2139,28 @@ export class OAuthService extends AuthConfig implements OnDestroy {
}

/*
* This alphabet uses a-z A-Z 0-9 _- symbols.
* Symbols order was changed for better gzip compression.
* This alphabet is from:
* https://tools.ietf.org/html/rfc7636#section-4.1
*
* [A-Z] / [a-z] / [0-9] / "-" / "." / "_" / "~"
*/
const url = 'Uint8ArdomValuesObj012345679BCDEFGHIJKLMNPQRSTWXYZ_cfghkpqvwxyz-';
const unreserved = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~';
let size = 45;
let id = '';

const crypto = self.crypto || self['msCrypto'];
if (crypto) {
const bytes = crypto.getRandomValues(new Uint8Array(size));
while (0 < size--) {
id += url[bytes[size] & 63];
}
let bytes = new Uint8Array(size);
crypto.getRandomValues(bytes);
bytes = bytes.map(x => unreserved.charCodeAt(x % unreserved.length));
id = String.fromCharCode.apply(null, bytes);
} else {
while (0 < size--) {
id += url[Math.random() * 64 | 0];
id += unreserved[Math.random() * unreserved.length | 0];
}
}

resolve(id);
resolve(base64UrlEncode(id));
});
}

Expand Down

0 comments on commit be8d273

Please sign in to comment.