mirror of
https://github.com/logto-io/logto.git
synced 2024-12-30 20:33:54 -05:00
chore(console): update custom JWT scripts sample (#5747)
This commit is contained in:
parent
e035377b83
commit
959f2d2795
2 changed files with 31 additions and 56 deletions
|
@ -111,6 +111,7 @@ function InstructionTab({ isActive }: Props) {
|
||||||
language="typescript"
|
language="typescript"
|
||||||
className={styles.sampleCode}
|
className={styles.sampleCode}
|
||||||
value={environmentVariablesCodeExample}
|
value={environmentVariablesCodeExample}
|
||||||
|
path="file:///env-variables-sample.js"
|
||||||
height="400px"
|
height="400px"
|
||||||
theme="logto-dark"
|
theme="logto-dark"
|
||||||
options={sampleCodeEditorOptions}
|
options={sampleCodeEditorOptions}
|
||||||
|
|
|
@ -20,70 +20,43 @@ import {
|
||||||
* JWT token code editor configuration
|
* JWT token code editor configuration
|
||||||
*/
|
*/
|
||||||
const accessTokenJwtCustomizerDefinition = `
|
const accessTokenJwtCustomizerDefinition = `
|
||||||
declare global {
|
declare interface CustomJwtClaims extends Record<string, any> {}
|
||||||
export interface CustomJwtClaims extends Record<string, any> {}
|
|
||||||
|
|
||||||
/** Logto internal data that can be used to pass additional information
|
/** Logto internal data that can be used to pass additional information
|
||||||
* @param {${JwtCustomizerTypeDefinitionKey.JwtCustomizerUserContext}} user - The user info associated with the token.
|
* @param {${JwtCustomizerTypeDefinitionKey.JwtCustomizerUserContext}} user - The user info associated with the token.
|
||||||
*/
|
*/
|
||||||
export type Data = {
|
declare type Context = {
|
||||||
user: ${JwtCustomizerTypeDefinitionKey.JwtCustomizerUserContext};
|
user: ${JwtCustomizerTypeDefinitionKey.JwtCustomizerUserContext};
|
||||||
}
|
|
||||||
|
|
||||||
export interface Exports {
|
|
||||||
/**
|
|
||||||
* This function is called during the access token generation process to get custom claims for the JWT token.
|
|
||||||
*
|
|
||||||
* @param {${JwtCustomizerTypeDefinitionKey.AccessTokenPayload}} token -The JWT token.
|
|
||||||
* @param {Data} data - Logto internal data that can be used to pass additional information
|
|
||||||
* @param {${JwtCustomizerTypeDefinitionKey.JwtCustomizerUserContext}} data.user - The user info associated with the token.
|
|
||||||
* @param {${JwtCustomizerTypeDefinitionKey.EnvironmentVariables}} envVariables - The environment variables.
|
|
||||||
*
|
|
||||||
* @returns The custom claims.
|
|
||||||
*/
|
|
||||||
getCustomJwtClaims: (token: ${JwtCustomizerTypeDefinitionKey.AccessTokenPayload}, data: Data, envVariables: ${JwtCustomizerTypeDefinitionKey.EnvironmentVariables}) => Promise<CustomJwtClaims>;
|
|
||||||
}
|
|
||||||
|
|
||||||
const exports: Exports;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export { exports as default };
|
declare type Payload = {
|
||||||
`;
|
token: ${JwtCustomizerTypeDefinitionKey.AccessTokenPayload};
|
||||||
|
context: Context;
|
||||||
|
environmentVariables: ${JwtCustomizerTypeDefinitionKey.EnvironmentVariables};
|
||||||
|
};`;
|
||||||
|
|
||||||
const clientCredentialsJwtCustomizerDefinition = `
|
const clientCredentialsJwtCustomizerDefinition = `
|
||||||
declare global {
|
declare interface CustomJwtClaims extends Record<string, any> {}
|
||||||
export interface CustomJwtClaims extends Record<string, any> {}
|
|
||||||
|
|
||||||
export interface Exports {
|
declare type Payload = {
|
||||||
/**
|
token: ${JwtCustomizerTypeDefinitionKey.AccessTokenPayload};
|
||||||
* This function is called during the access token generation process to get custom claims for the JWT token.
|
environmentVariables: ${JwtCustomizerTypeDefinitionKey.EnvironmentVariables};
|
||||||
*
|
};`;
|
||||||
* @param {${JwtCustomizerTypeDefinitionKey.ClientCredentialsPayload}} token -The JWT token.
|
|
||||||
*
|
|
||||||
* @returns The custom claims.
|
|
||||||
*/
|
|
||||||
getCustomJwtClaims: (token: ${JwtCustomizerTypeDefinitionKey.ClientCredentialsPayload}, envVariables: ${JwtCustomizerTypeDefinitionKey.EnvironmentVariables}) => Promise<CustomJwtClaims>;
|
|
||||||
}
|
|
||||||
|
|
||||||
const exports: Exports;
|
|
||||||
}
|
|
||||||
|
|
||||||
export { exports as default };
|
|
||||||
`;
|
|
||||||
|
|
||||||
export const defaultAccessTokenJwtCustomizerCode = `/**
|
export const defaultAccessTokenJwtCustomizerCode = `/**
|
||||||
* This function is called during the access token generation process to get custom claims for the JWT token.
|
* This function is called during the access token generation process to get custom claims for the JWT token.
|
||||||
* Limit custom claims to under 50KB.
|
* Limit custom claims to under 50KB.
|
||||||
*
|
*
|
||||||
* @param {${JwtCustomizerTypeDefinitionKey.AccessTokenPayload}} token -The JWT token.
|
* @param {Payload} payload - The input payload of the function.
|
||||||
* @param {Data} data - Logto internal data that can be used to pass additional information
|
* @param {${JwtCustomizerTypeDefinitionKey.AccessTokenPayload}} payload.token -The JWT token.
|
||||||
* @param {${JwtCustomizerTypeDefinitionKey.JwtCustomizerUserContext}} data.user - The user info associated with the token.
|
* @param {Context} payload.context - Logto internal data that can be used to pass additional information
|
||||||
* @param {${JwtCustomizerTypeDefinitionKey.EnvironmentVariables}} [envVariables] - The environment variables.
|
* @param {${JwtCustomizerTypeDefinitionKey.JwtCustomizerUserContext}} payload.context.user - The user info associated with the token.
|
||||||
|
* @param {${JwtCustomizerTypeDefinitionKey.EnvironmentVariables}} [payload.environmentVariables] - The environment variables.
|
||||||
*
|
*
|
||||||
* @returns The custom claims.
|
* @returns The custom claims.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.getCustomJwtClaims = async (token, data, envVariables) => {
|
const getCustomJwtClaims = async ({ token, context, environmentVariables }) => {
|
||||||
return {};
|
return {};
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
|
@ -91,13 +64,14 @@ export const defaultClientCredentialsJwtCustomizerCode = `/**
|
||||||
* This function is called during the access token generation process to get custom claims for the JWT token.
|
* This function is called during the access token generation process to get custom claims for the JWT token.
|
||||||
* Limit custom claims to under 50KB.
|
* Limit custom claims to under 50KB.
|
||||||
*
|
*
|
||||||
* @param {${JwtCustomizerTypeDefinitionKey.ClientCredentialsPayload}} token -The JWT token.
|
* @param {Payload} payload - The input payload of the function.
|
||||||
* @param {${JwtCustomizerTypeDefinitionKey.EnvironmentVariables}} [envVariables] - The environment variables.
|
* @param {${JwtCustomizerTypeDefinitionKey.ClientCredentialsPayload}} payload.token -The JWT token.
|
||||||
|
* @param {${JwtCustomizerTypeDefinitionKey.EnvironmentVariables}} [payload.environmentVariables] - The environment variables.
|
||||||
*
|
*
|
||||||
* @returns The custom claims.
|
* @returns The custom claims.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.getCustomJwtClaims = async (token, envVariables) => {
|
const getCustomJwtClaims = async ({ token, environmentVariables }) => {
|
||||||
return {};
|
return {};
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
|
@ -170,15 +144,15 @@ return {
|
||||||
externalData: data,
|
externalData: data,
|
||||||
};`;
|
};`;
|
||||||
|
|
||||||
export const environmentVariablesCodeExample = `exports.getCustomJwtClaims = async (token, data, envVariables) => {
|
export const environmentVariablesCodeExample = `const getCustomJwtClaimsSample = async ({ environmentVariables }) => {
|
||||||
const { apiKey } = envVariables;
|
const { apiKey } = environmentVariables;
|
||||||
|
|
||||||
const response = await fetch('https://api.example.com/data', {
|
const response = await fetch('https://api.example.com/data', {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: apiKey,
|
Authorization: apiKey,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in a new issue