Skip to content

Commit

Permalink
chore: prettier fix
Browse files Browse the repository at this point in the history
  • Loading branch information
coel committed Mar 19, 2024
1 parent f07053d commit 6cc94ab
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 36 deletions.
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Changelog


## b6bda8a4ff4564a6ae8fd8e180f3b57d2eaa5eb6...main

[compare changes](https://github.com/kinde-oss/kinde-typescript-sdk/compare/b6bda8a4ff4564a6ae8fd8e180f3b57d2eaa5eb6...main)
Expand Down Expand Up @@ -39,4 +38,3 @@
## 2.7.0...2.7.0

[compare changes](https://github.com/kinde-oss/kinde-typescript-sdk/compare/2.7.0...2.7.0)

3 changes: 1 addition & 2 deletions lib/__tests__/sdk/utilities/generateRandomString.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ describe('validateClientSecret', () => {
expect(result.length).toBe(25);
});


it('should return false for invalid secrets - odd length', () => {
const result = generateRandomString(47);
expect(result.length).toBe(47);
Expand All @@ -16,4 +15,4 @@ describe('validateClientSecret', () => {
const result = generateRandomString(50);
expect(result.length).toBe(50);
});
});
});
2 changes: 1 addition & 1 deletion lib/__tests__/sdk/utilities/validate-client-secret.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ describe('validateClientSecret', () => {
const result = validateClientSecret(invalidSecret);
expect(result).toBe(false);
});
});
});
12 changes: 5 additions & 7 deletions lib/sdk/clients/browser/authcode-with-pkce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import type {
BrowserPKCEClientOptions,
} from '../types.js';

import type {
OAuth2CodeExchangeResponse,
} from '../../oauth2-flows/types.js';
import type { OAuth2CodeExchangeResponse } from '../../oauth2-flows/types.js';

const createAuthCodeWithPKCEClient = (options: BrowserPKCEClientOptions) => {
const { featureFlags, tokenClaims } = utilities;
Expand Down Expand Up @@ -271,15 +269,15 @@ const createAuthCodeWithPKCEClient = (options: BrowserPKCEClientOptions) => {
const getToken = async (): Promise<string> => {
return await client.getToken(sessionManager);
};

/**
* Method makes user of the `refreshTokens` method of the `AuthCodeWithPKCE` client
* to use the refresh token to get new tokens
* @returns {Promise<OAuth2CodeExchangeResponse>}
*/
const refreshTokens = async (): Promise<OAuth2CodeExchangeResponse> => {
return await client.refreshTokens(sessionManager);
};
const refreshTokens = async (): Promise<OAuth2CodeExchangeResponse> => {
return await client.refreshTokens(sessionManager);
};

/**
* Method extracts the provided feature flag from the access token in the
Expand Down
8 changes: 4 additions & 4 deletions lib/sdk/clients/server/authorization-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import type {
ACClientOptions,
} from '../types.js';

import type {
OAuth2CodeExchangeResponse,
} from '../../oauth2-flows/types.js';
import type { OAuth2CodeExchangeResponse } from '../../oauth2-flows/types.js';

const createAuthorizationCodeClient = (
options: ACClientOptions,
Expand Down Expand Up @@ -143,7 +141,9 @@ const createAuthorizationCodeClient = (
* @param {SessionManager} sessionManager
* @returns {Promise<OAuth2CodeExchangeResponse>}
*/
const refreshTokens = async (sessionManager: SessionManager): Promise<OAuth2CodeExchangeResponse> => {
const refreshTokens = async (
sessionManager: SessionManager
): Promise<OAuth2CodeExchangeResponse> => {
return await client.refreshTokens(sessionManager);
};

Expand Down
26 changes: 16 additions & 10 deletions lib/sdk/oauth2-flows/AuthCodeAbstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export abstract class AuthCodeAbstract {
protected generateAuthURLParams(options: AuthURLOptions = {}): URLSearchParams {
const searchParams = this.getBaseAuthURLParams();

let scope = this.config.scope ?? AuthCodeAbstract.DEFAULT_TOKEN_SCOPES
let scope = this.config.scope ?? AuthCodeAbstract.DEFAULT_TOKEN_SCOPES;
scope = scope.split(' ').includes('openid') ? scope : `${scope} openid`;

let searchParamsObject: Record<string, unknown> = {
Expand All @@ -264,17 +264,22 @@ export abstract class AuthCodeAbstract {
}

if (options.authUrlParams) {
const { lang, login_hint: loginHint, connection_id: connectionId, ...rest } = options.authUrlParams;
const {
lang,
login_hint: loginHint,
connection_id: connectionId,
...rest
} = options.authUrlParams;
searchParamsObject = { ...rest, ...searchParamsObject };

if (lang) {
searchParamsObject.lang = lang;
}

if (loginHint) {
searchParamsObject.login_hint = loginHint;
}

if (connectionId) {
searchParamsObject.connection_id = connectionId;
}
Expand All @@ -290,12 +295,13 @@ export abstract class AuthCodeAbstract {
}

if (this.config.audience) {
const audienceArray = Array.isArray(this.config.audience) ? this.config.audience : [this.config.audience];
const audienceArray = Array.isArray(this.config.audience)
? this.config.audience
: [this.config.audience];

audienceArray
.forEach((aud) => {
searchParams.append('audience', aud);
});
audienceArray.forEach((aud) => {
searchParams.append('audience', aud);
});
}

return searchParams;
Expand Down
11 changes: 6 additions & 5 deletions lib/sdk/oauth2-flows/ClientCredentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,13 @@ export class ClientCredentials {
}

if (this.config.audience) {
const audienceArray = Array.isArray(this.config.audience) ? this.config.audience : [this.config.audience];
const audienceArray = Array.isArray(this.config.audience)
? this.config.audience
: [this.config.audience];

audienceArray
.forEach((aud) => {
searchParams.append('audience', aud);
});
audienceArray.forEach((aud) => {
searchParams.append('audience', aud);
});
}

return new URLSearchParams(searchParams);
Expand Down
6 changes: 4 additions & 2 deletions lib/sdk/utilities/random-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ export const generateRandomString = (length: number = 28): string => {
const bytesNeeded = Math.ceil(length / 2);
const array = new Uint32Array(bytesNeeded);
getRandomValues(array);
let result = Array.from(array, (dec) => ('0' + dec.toString(16)).slice(-2)).join('');
let result = Array.from(array, (dec) => ('0' + dec.toString(16)).slice(-2)).join(
''
);
if (length % 2 !== 0) {
// If the requested length is odd, remove the last character to adjust the length
result = result.slice(0, -1);
}
return result;
};
};
6 changes: 3 additions & 3 deletions lib/sdk/utilities/validate-client-secret.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* Validates that the supplied client secret is in the correct format.
* @param {string} secret
* @returns {boolean}
* @returns {boolean}
*/
export const validateClientSecret = (secret: string): boolean => {
return !!secret.match('^[a-zA-Z0-9]{40,60}$')?.length
};
return !!secret.match('^[a-zA-Z0-9]{40,60}$')?.length;
};

0 comments on commit 6cc94ab

Please sign in to comment.