Skip to content

Commit

Permalink
fix: PR changes
Browse files Browse the repository at this point in the history
  • Loading branch information
anku255 committed Jul 10, 2024
1 parent 769a049 commit 7cd08a1
Show file tree
Hide file tree
Showing 34 changed files with 422 additions and 651 deletions.
1 change: 1 addition & 0 deletions lib/build/recipe/oauth2client/api/authorisationUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ async function authorisationUrlAPI(apiImplementation, _tenantId, options, userCo
if (apiImplementation.authorisationUrlGET === undefined) {
return false;
}
// TODO: Check if we can rename `redirectURIOnProviderDashboard` to a more suitable name
const redirectURIOnProviderDashboard = options.req.getKeyValueFromQuery("redirectURIOnProviderDashboard");
if (redirectURIOnProviderDashboard === undefined || typeof redirectURIOnProviderDashboard !== "string") {
throw new error_1.default({
Expand Down
23 changes: 22 additions & 1 deletion lib/build/recipe/oauth2client/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
// @ts-nocheck
import Recipe from "./recipe";
import { RecipeInterface, APIInterface, APIOptions } from "./types";
import { RecipeInterface, APIInterface, APIOptions, ProviderConfigWithOIDCInfo, OAuthTokens } from "./types";
export default class Wrapper {
static init: typeof Recipe.init;
static getAuthorisationRedirectURL(input: {
redirectURIOnProviderDashboard: string;
}): Promise<{
urlWithQueryParams: string;
pkceCodeVerifier?: string | undefined;
}>;
static exchangeAuthCodeForOAuthTokens(input: {
providerConfig: ProviderConfigWithOIDCInfo;
redirectURIInfo: {
redirectURIOnProviderDashboard: string;
redirectURIQueryParams: any;
pkceCodeVerifier?: string | undefined;
};
}): Promise<import("./types").OAuthTokenResponse>;
static getUserInfo(input: {
providerConfig: ProviderConfigWithOIDCInfo;
oAuthTokens: OAuthTokens;
}): Promise<import("./types").UserInfo>;
}
export declare let init: typeof Recipe.init;
export declare let getAuthorisationRedirectURL: typeof Wrapper.getAuthorisationRedirectURL;
export declare let exchangeAuthCodeForOAuthTokens: typeof Wrapper.exchangeAuthCodeForOAuthTokens;
export declare let getUserInfo: typeof Wrapper.getUserInfo;
export type { RecipeInterface, APIInterface, APIOptions };
19 changes: 17 additions & 2 deletions lib/build/recipe/oauth2client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,24 @@ var __importDefault =
return mod && mod.__esModule ? mod : { default: mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.init = void 0;
exports.getUserInfo = exports.exchangeAuthCodeForOAuthTokens = exports.getAuthorisationRedirectURL = exports.init = void 0;
const recipe_1 = __importDefault(require("./recipe"));
class Wrapper {}
class Wrapper {
static async getAuthorisationRedirectURL(input) {
return await recipe_1.default.getInstanceOrThrowError().recipeInterfaceImpl.getAuthorisationRedirectURL(input);
}
static async exchangeAuthCodeForOAuthTokens(input) {
return await recipe_1.default
.getInstanceOrThrowError()
.recipeInterfaceImpl.exchangeAuthCodeForOAuthTokens(input);
}
static async getUserInfo(input) {
return await recipe_1.default.getInstanceOrThrowError().recipeInterfaceImpl.getUserInfo(input);
}
}
exports.default = Wrapper;
Wrapper.init = recipe_1.default.init;
exports.init = Wrapper.init;
exports.getAuthorisationRedirectURL = Wrapper.getAuthorisationRedirectURL;
exports.exchangeAuthCodeForOAuthTokens = Wrapper.exchangeAuthCodeForOAuthTokens;
exports.getUserInfo = Wrapper.getUserInfo;
2 changes: 1 addition & 1 deletion lib/build/recipe/oauth2client/recipeImplementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var __importDefault =
};
Object.defineProperty(exports, "__esModule", { value: true });
const recipeUserId_1 = __importDefault(require("../../recipeUserId"));
const utils_1 = require("./utils");
const utils_1 = require("../utils");
const pkce_challenge_1 = __importDefault(require("pkce-challenge"));
const __1 = require("../..");
const logger_1 = require("../../logger");
Expand Down
24 changes: 16 additions & 8 deletions lib/build/recipe/oauth2client/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ export declare type ProviderConfigWithOIDCInfo = ProviderConfigInput & {
userInfoEndpoint: string;
jwksURI: string;
};
export declare type OAuthTokens = {
access_token?: string;
id_token?: string;
};
export declare type OAuthTokenResponse = {
access_token: string;
id_token?: string;
refresh_token?: string;
expires_in: number;
scope?: string;
token_type: string;
};
export declare type TypeInput = {
providerConfig: ProviderConfigInput;
override?: {
Expand Down Expand Up @@ -62,9 +74,7 @@ export declare type RecipeInterface = {
getProviderConfig(input: { userContext: UserContext }): Promise<ProviderConfigWithOIDCInfo>;
signIn(input: {
userId: string;
oAuthTokens: {
[key: string]: any;
};
oAuthTokens: OAuthTokens;
rawUserInfoFromProvider: {
fromIdTokenPayload?: {
[key: string]: any;
Expand All @@ -79,9 +89,7 @@ export declare type RecipeInterface = {
status: "OK";
recipeUserId: RecipeUserId;
user: User;
oAuthTokens: {
[key: string]: any;
};
oAuthTokens: OAuthTokens;
rawUserInfoFromProvider: {
fromIdTokenPayload?: {
[key: string]: any;
Expand All @@ -98,8 +106,8 @@ export declare type RecipeInterface = {
redirectURIQueryParams: any;
pkceCodeVerifier?: string | undefined;
};
}): Promise<Record<string, any> | undefined>;
getUserInfo(input: { providerConfig: ProviderConfigWithOIDCInfo; oAuthTokens: any }): Promise<UserInfo>;
}): Promise<OAuthTokenResponse>;
getUserInfo(input: { providerConfig: ProviderConfigWithOIDCInfo; oAuthTokens: OAuthTokens }): Promise<UserInfo>;
};
export declare type APIOptions = {
recipeImplementation: RecipeInterface;
Expand Down
33 changes: 0 additions & 33 deletions lib/build/recipe/oauth2client/utils.d.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,7 @@
// @ts-nocheck
import { NormalisedAppinfo } from "../../types";
import { TypeInput, TypeNormalisedInput } from "./types";
import * as jose from "jose";
export declare function validateAndNormaliseUserInput(
_appInfo: NormalisedAppinfo,
config: TypeInput
): TypeNormalisedInput;
export declare function doGetRequest(
url: string,
queryParams?: {
[key: string]: string;
},
headers?: {
[key: string]: string;
}
): Promise<{
jsonResponse: Record<string, any> | undefined;
status: number;
stringResponse: string;
}>;
export declare function doPostRequest(
url: string,
params: {
[key: string]: any;
},
headers?: {
[key: string]: string;
}
): Promise<{
jsonResponse: Record<string, any> | undefined;
status: number;
stringResponse: string;
}>;
export declare function verifyIdTokenFromJWKSEndpointAndGetPayload(
idToken: string,
jwks: jose.JWTVerifyGetKey,
otherOptions: jose.JWTVerifyOptions
): Promise<any>;
export declare function getOIDCDiscoveryInfo(issuer: string): Promise<any>;
129 changes: 1 addition & 128 deletions lib/build/recipe/oauth2client/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,54 +13,8 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
var __createBinding =
(this && this.__createBinding) ||
(Object.create
? function (o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, {
enumerable: true,
get: function () {
return m[k];
},
});
}
: function (o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
});
var __setModuleDefault =
(this && this.__setModuleDefault) ||
(Object.create
? function (o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}
: function (o, v) {
o["default"] = v;
});
var __importStar =
(this && this.__importStar) ||
function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null)
for (var k in mod)
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault =
(this && this.__importDefault) ||
function (mod) {
return mod && mod.__esModule ? mod : { default: mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getOIDCDiscoveryInfo = exports.verifyIdTokenFromJWKSEndpointAndGetPayload = exports.doPostRequest = exports.doGetRequest = exports.validateAndNormaliseUserInput = void 0;
const jose = __importStar(require("jose"));
const normalisedURLDomain_1 = __importDefault(require("../../normalisedURLDomain"));
const normalisedURLPath_1 = __importDefault(require("../../normalisedURLPath"));
const utils_1 = require("../../utils");
const logger_1 = require("../../logger");
exports.validateAndNormaliseUserInput = void 0;
function validateAndNormaliseUserInput(_appInfo, config) {
if (config === undefined || config.providerConfig === undefined) {
throw new Error("Please pass providerConfig argument in the OAuth2Client recipe.");
Expand Down Expand Up @@ -93,84 +47,3 @@ function validateAndNormaliseUserInput(_appInfo, config) {
};
}
exports.validateAndNormaliseUserInput = validateAndNormaliseUserInput;
async function doGetRequest(url, queryParams, headers) {
logger_1.logDebugMessage(
`GET request to ${url}, with query params ${JSON.stringify(queryParams)} and headers ${JSON.stringify(headers)}`
);
if ((headers === null || headers === void 0 ? void 0 : headers["Accept"]) === undefined) {
headers = Object.assign(Object.assign({}, headers), { Accept: "application/json" });
}
const finalURL = new URL(url);
finalURL.search = new URLSearchParams(queryParams).toString();
let response = await utils_1.doFetch(finalURL.toString(), {
headers: headers,
});
const stringResponse = await response.text();
let jsonResponse = undefined;
if (response.status < 400) {
jsonResponse = JSON.parse(stringResponse);
}
logger_1.logDebugMessage(`Received response with status ${response.status} and body ${stringResponse}`);
return {
stringResponse,
status: response.status,
jsonResponse,
};
}
exports.doGetRequest = doGetRequest;
async function doPostRequest(url, params, headers) {
if (headers === undefined) {
headers = {};
}
headers["Content-Type"] = "application/x-www-form-urlencoded";
headers["Accept"] = "application/json";
logger_1.logDebugMessage(
`POST request to ${url}, with params ${JSON.stringify(params)} and headers ${JSON.stringify(headers)}`
);
const body = new URLSearchParams(params).toString();
let response = await utils_1.doFetch(url, {
method: "POST",
body,
headers,
});
const stringResponse = await response.text();
let jsonResponse = undefined;
if (response.status < 400) {
jsonResponse = JSON.parse(stringResponse);
}
logger_1.logDebugMessage(`Received response with status ${response.status} and body ${stringResponse}`);
return {
stringResponse,
status: response.status,
jsonResponse,
};
}
exports.doPostRequest = doPostRequest;
async function verifyIdTokenFromJWKSEndpointAndGetPayload(idToken, jwks, otherOptions) {
const { payload } = await jose.jwtVerify(idToken, jwks, otherOptions);
return payload;
}
exports.verifyIdTokenFromJWKSEndpointAndGetPayload = verifyIdTokenFromJWKSEndpointAndGetPayload;
// OIDC utils
var oidcInfoMap = {};
async function getOIDCDiscoveryInfo(issuer) {
const normalizedDomain = new normalisedURLDomain_1.default(issuer);
let normalizedPath = new normalisedURLPath_1.default(issuer);
const openIdConfigPath = new normalisedURLPath_1.default("/.well-known/openid-configuration");
normalizedPath = normalizedPath.appendPath(openIdConfigPath);
if (oidcInfoMap[issuer] !== undefined) {
return oidcInfoMap[issuer];
}
const oidcInfo = await doGetRequest(
normalizedDomain.getAsStringDangerous() + normalizedPath.getAsStringDangerous()
);
if (oidcInfo.status >= 400) {
logger_1.logDebugMessage(
`Received response with status ${oidcInfo.status} and body ${oidcInfo.stringResponse}`
);
throw new Error(`Received response with status ${oidcInfo.status} and body ${oidcInfo.stringResponse}`);
}
oidcInfoMap[issuer] = oidcInfo.jsonResponse;
return oidcInfo.jsonResponse;
}
exports.getOIDCDiscoveryInfo = getOIDCDiscoveryInfo;
2 changes: 1 addition & 1 deletion lib/build/recipe/thirdparty/providers/bitbucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var __importDefault =
return mod && mod.__esModule ? mod : { default: mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("./utils");
const utils_1 = require("../../utils");
const custom_1 = __importDefault(require("./custom"));
const logger_1 = require("../../../logger");
function Bitbucket(input) {
Expand Down
2 changes: 1 addition & 1 deletion lib/build/recipe/thirdparty/providers/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var __importDefault =
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getActualClientIdFromDevelopmentClientId = exports.isUsingDevelopmentClientId = exports.DEV_OAUTH_REDIRECT_URL = void 0;
const utils_1 = require("./utils");
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
2 changes: 1 addition & 1 deletion lib/build/recipe/thirdparty/providers/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var __importDefault =
};
Object.defineProperty(exports, "__esModule", { value: true });
const custom_1 = __importDefault(require("./custom"));
const utils_1 = require("./utils");
const utils_1 = require("../../utils");
function getSupertokensUserInfoFromRawUserInfoResponseForGithub(rawUserInfoResponse) {
if (rawUserInfoResponse.fromUserInfoAPI === undefined) {
throw new Error("rawUserInfoResponse.fromUserInfoAPI is not available");
Expand Down
2 changes: 1 addition & 1 deletion lib/build/recipe/thirdparty/providers/linkedin.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
*/
const logger_1 = require("../../../logger");
const custom_1 = __importDefault(require("./custom"));
const utils_1 = require("./utils");
const utils_1 = require("../../utils");
function Linkedin(input) {
if (input.config.name === undefined) {
input.config.name = "LinkedIn";
Expand Down
2 changes: 1 addition & 1 deletion lib/build/recipe/thirdparty/providers/twitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
*/
const logger_1 = require("../../../logger");
const custom_1 = __importStar(require("./custom"));
const utils_1 = require("./utils");
const utils_1 = require("../../utils");
function Twitter(input) {
var _a;
if (input.config.name === undefined) {
Expand Down
32 changes: 0 additions & 32 deletions lib/build/recipe/thirdparty/providers/utils.d.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,3 @@
// @ts-nocheck
import * as jose from "jose";
import { ProviderConfigForClientType } from "../types";
export declare function doGetRequest(
url: string,
queryParams?: {
[key: string]: string;
},
headers?: {
[key: string]: string;
}
): Promise<{
jsonResponse: Record<string, any> | undefined;
status: number;
stringResponse: string;
}>;
export declare function doPostRequest(
url: string,
params: {
[key: string]: any;
},
headers?: {
[key: string]: string;
}
): Promise<{
jsonResponse: Record<string, any> | undefined;
status: number;
stringResponse: string;
}>;
export declare function verifyIdTokenFromJWKSEndpointAndGetPayload(
idToken: string,
jwks: jose.JWTVerifyGetKey,
otherOptions: jose.JWTVerifyOptions
): Promise<any>;
export declare function discoverOIDCEndpoints(config: ProviderConfigForClientType): Promise<void>;
Loading

0 comments on commit 7cd08a1

Please sign in to comment.