Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
thivi committed Feb 28, 2022
1 parent 03fc77d commit 511d598
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 31 deletions.
13 changes: 8 additions & 5 deletions lib/src/core/authentication-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class AuthenticationCore<T> {
"getAuthorizationURL",
"No authorization endpoint found.",
"No authorization endpoint was found in the OIDC provider meta data from the well-known endpoint " +
"or the authorization endpoint passed to the SDK is empty."
"or the authorization endpoint passed to the SDK is empty."
);
}

Expand Down Expand Up @@ -118,7 +118,7 @@ export class AuthenticationCore<T> {

const customParams = config;
if (customParams) {
for (const [key, value] of Object.entries(customParams)) {
for (const [ key, value ] of Object.entries(customParams)) {
if (key != "" && value != "") {
authorizeRequest.searchParams.append(key, value.toString());
}
Expand All @@ -133,7 +133,6 @@ export class AuthenticationCore<T> {
)
);


return authorizeRequest.toString();
}

Expand Down Expand Up @@ -175,8 +174,12 @@ export class AuthenticationCore<T> {
body.push(`redirect_uri=${ configData.signInRedirectURL }`);

if (configData.enablePKCE) {
body.push(`code_verifier=${ await this._dataLayer.getTemporaryDataParameter(
AuthenticationUtils.extractPKCEKeyFromStateParam(state), userID) }`);
body.push(
`code_verifier=${ await this._dataLayer.getTemporaryDataParameter(
AuthenticationUtils.extractPKCEKeyFromStateParam(state),
userID
) }`
);

await this._dataLayer.removeTemporaryDataParameter(
AuthenticationUtils.extractPKCEKeyFromStateParam(state),
Expand Down
39 changes: 19 additions & 20 deletions lib/src/helpers/authentication-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ export class AuthenticationHelper<T> {
if (configData.overrideWellEndpointConfig) {
configData.endpoints &&
Object.keys(configData.endpoints).forEach((endpointName: string) => {
const snakeCasedName = endpointName.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
oidcProviderMetaData[snakeCasedName] = configData?.endpoints
? configData.endpoints[endpointName]
const snakeCasedName = endpointName.replace(/[A-Z]/g, (letter) => `_${ letter.toLowerCase() }`);
oidcProviderMetaData[ snakeCasedName ] = configData?.endpoints
? configData.endpoints[ endpointName ]
: "";
});
}
Expand All @@ -95,17 +95,17 @@ export class AuthenticationHelper<T> {

configData.endpoints &&
Object.keys(configData.endpoints).forEach((endpointName: string) => {
const snakeCasedName = endpointName.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
oidcProviderMetaData[snakeCasedName] = configData?.endpoints ? configData.endpoints[endpointName] : "";
const snakeCasedName = endpointName.replace(/[A-Z]/g, (letter) => `_${ letter.toLowerCase() }`);
oidcProviderMetaData[ snakeCasedName ] = configData?.endpoints ? configData.endpoints[ endpointName ] : "";
});

const defaultEndpoints = {
[AUTHORIZATION_ENDPOINT]: configData.serverOrigin + SERVICE_RESOURCES.authorizationEndpoint,
[END_SESSION_ENDPOINT]: configData.serverOrigin + SERVICE_RESOURCES.endSessionEndpoint,
[JWKS_ENDPOINT]: configData.serverOrigin + SERVICE_RESOURCES.jwksUri,
[OIDC_SESSION_IFRAME_ENDPOINT]: configData.serverOrigin + SERVICE_RESOURCES.checkSessionIframe,
[REVOKE_TOKEN_ENDPOINT]: configData.serverOrigin + SERVICE_RESOURCES.revocationEndpoint,
[TOKEN_ENDPOINT]: configData.serverOrigin + SERVICE_RESOURCES.tokenEndpoint
[ AUTHORIZATION_ENDPOINT ]: configData.serverOrigin + SERVICE_RESOURCES.authorizationEndpoint,
[ END_SESSION_ENDPOINT ]: configData.serverOrigin + SERVICE_RESOURCES.endSessionEndpoint,
[ JWKS_ENDPOINT ]: configData.serverOrigin + SERVICE_RESOURCES.jwksUri,
[ OIDC_SESSION_IFRAME_ENDPOINT ]: configData.serverOrigin + SERVICE_RESOURCES.checkSessionIframe,
[ REVOKE_TOKEN_ENDPOINT ]: configData.serverOrigin + SERVICE_RESOURCES.revocationEndpoint,
[ TOKEN_ENDPOINT ]: configData.serverOrigin + SERVICE_RESOURCES.tokenEndpoint
};

return { ...oidcProviderMetaData, ...defaultEndpoints };
Expand All @@ -123,7 +123,7 @@ export class AuthenticationHelper<T> {
"validateIdToken",
"JWKS endpoint not found.",
"No JWKS endpoint was found in the OIDC provider meta data returned by the well-known endpoint " +
"or the JWKS endpoint passed to the SDK is empty."
"or the JWKS endpoint passed to the SDK is empty."
)
);
}
Expand All @@ -148,7 +148,7 @@ export class AuthenticationHelper<T> {
}

const issuer = (await this._oidcProviderMetaData()).issuer;
const issuerFromURL = (await this.resolveWellKnownEndpoint()).split("/.well-known")[0];
const issuerFromURL = (await this.resolveWellKnownEndpoint()).split("/.well-known")[ 0 ];

// Return false if the issuer in the open id config doesn't match
// the issuer in the well known endpoint URL.
Expand All @@ -158,7 +158,7 @@ export class AuthenticationHelper<T> {
const parsedResponse = await response.json();

return this._cryptoHelper
.getJWKForTheIdToken(idToken.split(".")[0], parsedResponse.keys)
.getJWKForTheIdToken(idToken.split(".")[ 0 ], parsedResponse.keys)
.then(async (jwk: any) => {
return this._cryptoHelper
.isValidIdToken(
Expand Down Expand Up @@ -221,12 +221,12 @@ export class AuthenticationHelper<T> {
const familyName: string = payload.family_name ?? "";
const fullName: string =
givenName && familyName
? `${givenName} ${familyName}`
? `${ givenName } ${ familyName }`
: givenName
? givenName
: familyName
? familyName
: "";
? givenName
: familyName
? familyName
: "";
const displayName: string = payload.preferred_username ?? fullName;

return {
Expand Down Expand Up @@ -351,7 +351,6 @@ export class AuthenticationHelper<T> {
});

const lastKey: string | undefined = keys.sort().pop();

const index: number = parseInt(lastKey?.split(PKCE_SEPARATOR)[ 1 ] ?? "-1");

return `${ PKCE_CODE_VERIFIER }${ PKCE_SEPARATOR }${ index + 1 }`;
Expand Down
12 changes: 6 additions & 6 deletions lib/src/utils/authentication-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { DecodedIDTokenPayload } from "../models";

export class AuthenticationUtils {
// eslint-disable-next-line @typescript-eslint/no-empty-function
private constructor() {}
private constructor() { }

public static filterClaimsFromIDTokenPayload(payload: DecodedIDTokenPayload): any {
const optionalizedPayload: Partial<DecodedIDTokenPayload> = { ...payload };
Expand All @@ -42,19 +42,19 @@ export class AuthenticationUtils {
delete optionalizedPayload?.sid;

const camelCasedPayload = {};
Object.entries(optionalizedPayload).forEach(([key, value]) => {
Object.entries(optionalizedPayload).forEach(([ key, value ]) => {
const keyParts = key.split("_");
const camelCasedKey = keyParts
.map((key: string, index: number) => {
if (index === 0) {
return key;
}

return [key[0].toUpperCase(), ...key.slice(1)].join("");
return [ key[ 0 ].toUpperCase(), ...key.slice(1) ].join("");
})
.join("");

camelCasedPayload[camelCasedKey] = value;
camelCasedPayload[ camelCasedKey ] = value;
});

return camelCasedPayload;
Expand All @@ -70,7 +70,7 @@ export class AuthenticationUtils {

// This works only when the email is used as the username
// and the tenant domain is appended to the`sub` attribute.
return tokens.length > 2 ? tokens[tokens.length - 1] : "";
return tokens.length > 2 ? tokens[ tokens.length - 1 ] : "";
};

public static getTokenRequestHeaders(): HeadersInit {
Expand All @@ -97,6 +97,6 @@ export class AuthenticationUtils {
public static extractPKCEKeyFromStateParam(stateParam: string): string {
const index: number = parseInt(stateParam.split("request_")[ 1 ]);

return `${ PKCE_CODE_VERIFIER }${PKCE_SEPARATOR}${ index }`;
return `${ PKCE_CODE_VERIFIER }${ PKCE_SEPARATOR }${ index }`;
}
}

0 comments on commit 511d598

Please sign in to comment.