Skip to content
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

response Mode #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,4 @@ typings/

# DynamoDB Local files
.dynamodb/
.idea/
15 changes: 7 additions & 8 deletions source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@ const getAuthorizationUrl = (options = {}) => {
url.searchParams.append('state', options.state || 'state');
url.searchParams.append('client_id', options.clientID);
url.searchParams.append('redirect_uri', options.redirectUri);
url.searchParams.append('response_mode', options.responseMode);

if (options.scope){
url.searchParams.append('scope', 'openid ' + options.scope);
} else {
url.searchParams.append('scope', 'openid');
if (options.scope) {
url.searchParams.append('scope', `openid ${options.scope || DEFAULT_SCOPE}`);
}

return url.toString();
};

const getClientSecret = options => {
const getClientSecret = (options) => {
if (!options.clientID) throw new Error('clientID is empty');
if (!options.teamId) throw new Error('teamId is empty');
if (!options.keyIdentifier) throw new Error('keyIdentifier is empty');
Expand Down Expand Up @@ -106,8 +105,8 @@ const verifyIdToken = async (idToken, clientID) => {
const applePublicKey = await getApplePublicKey();
const jwtClaims = jwt.verify(idToken, applePublicKey, { algorithms: 'RS256' });

if (jwtClaims.iss !== TOKEN_ISSUER) throw new Error('id token not issued by correct OpenID provider - expected: ' + TOKEN_ISSUER + ' | from: ' + jwtClaims.iss);
if (clientID !== undefined && jwtClaims.aud !== clientID) throw new Error('aud parameter does not include this client - is: ' + jwtClaims.aud + '| expected: ' + clientID);
if (jwtClaims.iss !== TOKEN_ISSUER) throw new Error(`id token not issued by correct OpenID provider - expected: ${TOKEN_ISSUER} | from: ${jwtClaims.iss}`);
if (clientID !== undefined && jwtClaims.aud !== clientID) throw new Error(`aud parameter does not include this client - is: ${jwtClaims.aud}| expected: ${clientID}`);
if (jwtClaims.exp < (Date.now() / 1000)) throw new Error('id token has expired');

return jwtClaims;
Expand All @@ -119,5 +118,5 @@ module.exports = {
getAuthorizationToken,
refreshAuthorizationToken,
verifyIdToken,
getClientSecret
getClientSecret,
};