Skip to content

Commit

Permalink
refactor(types): Minor Type Improvements for the ThirdParty Recipe (#…
Browse files Browse the repository at this point in the history
…946)

* refactor(types): Make `userContext` in `TypeProvider` methods optional

It is safe to pass `undefined` for `userContext` in all of these
cases. Therefore, to improve the DX for developers not leveraging
`UserContext` for these methods, the argument should be optional.

* refactor(types): Clarify `redirectURIQueryParams` Type

This argument expects an object of strings. This should be
clarified to developers so that they don't mistakenly pass,
for instance, an instance of `URLSearchParams`.

* chore: Changelog updates

---------

Co-authored-by: Rishabh Poddar <rishabh.poddar@gmail.com>
  • Loading branch information
ITenthusiasm and rishabhpoddar authored Oct 19, 2024
1 parent 4545368 commit 7c9e78a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- The `networkInterceptor` now also gets a new `params` prop in the request config.
- Adds `customFramework` util functions to minimize code required in custom frameworks like remix, astro etc.
- Replicates `fastify` types based on requirement for the SDK instead of using the original module.
- Improved type definitions for `TypeProvider`

### Breaking change

Expand Down
5 changes: 3 additions & 2 deletions lib/build/recipe/thirdparty/providers/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var __importDefault =
Object.defineProperty(exports, "__esModule", { value: true });
exports.getActualClientIdFromDevelopmentClientId = exports.isUsingDevelopmentClientId = exports.DEV_OAUTH_REDIRECT_URL = void 0;
const thirdpartyUtils_1 = require("../../../thirdpartyUtils");
const utils_1 = require("../../../utils");
const pkce_challenge_1 = __importDefault(require("pkce-challenge"));
const configUtils_1 = require("./configUtils");
const jose_1 = require("jose");
Expand Down Expand Up @@ -284,15 +285,15 @@ function NewProvider(input) {
await impl.config.validateIdTokenPayload({
idTokenPayload: rawUserInfoFromProvider.fromIdTokenPayload,
clientConfig: impl.config,
userContext,
userContext: utils_1.getUserContext(userContext),
});
}
}
if (impl.config.validateAccessToken !== undefined && accessToken !== undefined) {
await impl.config.validateAccessToken({
accessToken: accessToken,
clientConfig: impl.config,
userContext,
userContext: utils_1.getUserContext(userContext),
});
}
if (accessToken && impl.config.userInfoEndpoint !== undefined) {
Expand Down
10 changes: 5 additions & 5 deletions lib/build/recipe/thirdparty/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,24 @@ export declare type TypeProvider = {
config: ProviderConfigForClientType;
getConfigForClientType: (input: {
clientType?: string;
userContext: UserContext;
userContext?: UserContext;
}) => Promise<ProviderConfigForClientType>;
getAuthorisationRedirectURL: (input: {
redirectURIOnProviderDashboard: string;
userContext: UserContext;
userContext?: UserContext;
}) => Promise<{
urlWithQueryParams: string;
pkceCodeVerifier?: string;
}>;
exchangeAuthCodeForOAuthTokens: (input: {
redirectURIInfo: {
redirectURIOnProviderDashboard: string;
redirectURIQueryParams: any;
redirectURIQueryParams: Record<string, string>;
pkceCodeVerifier?: string;
};
userContext: UserContext;
userContext?: UserContext;
}) => Promise<any>;
getUserInfo: (input: { oAuthTokens: any; userContext: UserContext }) => Promise<UserInfo>;
getUserInfo: (input: { oAuthTokens: any; userContext?: UserContext }) => Promise<UserInfo>;
};
export declare type ProviderConfig = CommonProviderConfig & {
clients?: ProviderClientConfig[];
Expand Down
5 changes: 3 additions & 2 deletions lib/ts/recipe/thirdparty/providers/custom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { TypeProvider, ProviderInput, UserInfo, ProviderConfigForClientType } from "../types";
import { doGetRequest, doPostRequest, verifyIdTokenFromJWKSEndpointAndGetPayload } from "../../../thirdpartyUtils";
import { getUserContext } from "../../../utils";
import pkceChallenge from "pkce-challenge";
import { getProviderConfigForClient } from "./configUtils";
import { JWTVerifyGetKey, createRemoteJWKSet } from "jose";
Expand Down Expand Up @@ -312,7 +313,7 @@ export default function NewProvider(input: ProviderInput): TypeProvider {
await impl.config.validateIdTokenPayload({
idTokenPayload: rawUserInfoFromProvider.fromIdTokenPayload,
clientConfig: impl.config,
userContext,
userContext: getUserContext(userContext),
});
}
}
Expand All @@ -321,7 +322,7 @@ export default function NewProvider(input: ProviderInput): TypeProvider {
await impl.config.validateAccessToken({
accessToken: accessToken,
clientConfig: impl.config,
userContext,
userContext: getUserContext(userContext),
});
}

Expand Down
10 changes: 5 additions & 5 deletions lib/ts/recipe/thirdparty/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,21 @@ export type TypeProvider = {

getConfigForClientType: (input: {
clientType?: string;
userContext: UserContext;
userContext?: UserContext;
}) => Promise<ProviderConfigForClientType>;
getAuthorisationRedirectURL: (input: {
redirectURIOnProviderDashboard: string;
userContext: UserContext;
userContext?: UserContext;
}) => Promise<{ urlWithQueryParams: string; pkceCodeVerifier?: string }>;
exchangeAuthCodeForOAuthTokens: (input: {
redirectURIInfo: {
redirectURIOnProviderDashboard: string;
redirectURIQueryParams: any;
redirectURIQueryParams: Record<string, string>;
pkceCodeVerifier?: string;
};
userContext: UserContext;
userContext?: UserContext;
}) => Promise<any>;
getUserInfo: (input: { oAuthTokens: any; userContext: UserContext }) => Promise<UserInfo>;
getUserInfo: (input: { oAuthTokens: any; userContext?: UserContext }) => Promise<UserInfo>;
};

export type ProviderConfig = CommonProviderConfig & {
Expand Down

0 comments on commit 7c9e78a

Please sign in to comment.