Skip to content

Correct implementation of rfc7636 section 4.1 #629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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