Skip to content

Commit

Permalink
Merge pull request #53 from kinde-oss/feat/ts-improvements
Browse files Browse the repository at this point in the history
feat: TS enhancements
  • Loading branch information
coel authored Mar 13, 2024
2 parents 52e5bba + 8260be4 commit 5e27c7f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
31 changes: 23 additions & 8 deletions lib/sdk/oauth2-flows/AuthCodeAbstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export abstract class AuthCodeAbstract {
let scope = this.config.scope ?? AuthCodeAbstract.DEFAULT_TOKEN_SCOPES
scope = scope.split(' ').includes('openid') ? scope : `${scope} openid`;

let searchParamsObject: Record<string, string> = {
let searchParamsObject: Record<string, unknown> = {
scope,
};

Expand All @@ -263,16 +263,31 @@ export abstract class AuthCodeAbstract {
searchParamsObject.is_create_org = 'true';
}

if (options.post_login_redirect_url) {
searchParamsObject.post_login_redirect_url = options.post_login_redirect_url;
}

if (options.authUrlParams) {
searchParamsObject = { ...options.authUrlParams, ...searchParamsObject };
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;
}
}

for (const key in searchParamsObject)
searchParams.append(key, searchParamsObject[key]);
for (const key in searchParamsObject) {
const value = searchParamsObject[key];
if (typeof value === 'object' && value !== null) {
searchParams.append(key, JSON.stringify(value));
} else {
searchParams.append(key, String(value));
}
}

if (this.config.audience) {
const audienceArray = Array.isArray(this.config.audience) ? this.config.audience : [this.config.audience];
Expand Down
9 changes: 8 additions & 1 deletion lib/sdk/oauth2-flows/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,19 @@ export interface ClientCredentialsOptions
clientSecret: string;
}

export interface AuthURLParams {
lang?: string;
login_hint?: string;
connection_id?: string;
[key: string]: string | undefined;
}

export interface AuthURLOptions {
start_page?: 'registration' | 'login';
is_create_org?: boolean;
org_name?: string;
org_code?: string;
state?: string;
post_login_redirect_url?: string;
authUrlParams?: Record<string, string>;
authUrlParams?: AuthURLParams;
}
4 changes: 2 additions & 2 deletions lib/sdk/session-managers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
type Awaitable<T> = Promise<T>;

export interface SessionManager {
getSessionItem: (itemKey: string) => Awaitable<unknown | null>;
setSessionItem: (itemKey: string, itemValue: unknown) => Awaitable<void>;
getSessionItem: <T = unknown>(itemKey: string) => Awaitable<T | unknown | null>;
setSessionItem: <T = unknown>(itemKey: string, itemValue: T) => Awaitable<void>;
removeSessionItem: (itemKey: string) => Awaitable<void>;
destroySession: () => Awaitable<void>;
}

0 comments on commit 5e27c7f

Please sign in to comment.