2022-10-09 17:22:34 +08:00
|
|
|
import crypto from 'crypto';
|
2022-04-21 16:13:59 +08:00
|
|
|
|
2022-10-21 13:14:17 +08:00
|
|
|
import type { LogtoOidcConfigType } from '@logto/schemas';
|
|
|
|
import { LogtoOidcConfigKey } from '@logto/schemas';
|
2022-08-08 14:00:24 +08:00
|
|
|
import { createLocalJWKSet } from 'jose';
|
2022-04-21 16:13:59 +08:00
|
|
|
|
2022-08-08 14:00:24 +08:00
|
|
|
import { exportJWK } from '@/utils/jwks';
|
|
|
|
|
2022-10-09 17:22:34 +08:00
|
|
|
const loadOidcValues = async (issuer: string, configs: LogtoOidcConfigType) => {
|
|
|
|
const cookieKeys = configs[LogtoOidcConfigKey.CookieKeys];
|
|
|
|
const privateKeys = configs[LogtoOidcConfigKey.PrivateKeys].map((key) =>
|
|
|
|
crypto.createPrivateKey(key)
|
2022-08-08 14:00:24 +08:00
|
|
|
);
|
|
|
|
const publicKeys = privateKeys.map((key) => crypto.createPublicKey(key));
|
|
|
|
const privateJwks = await Promise.all(privateKeys.map(async (key) => exportJWK(key)));
|
|
|
|
const publicJwks = await Promise.all(publicKeys.map(async (key) => exportJWK(key)));
|
|
|
|
const localJWKSet = createLocalJWKSet({ keys: publicJwks });
|
2022-10-09 17:22:34 +08:00
|
|
|
const refreshTokenReuseInterval = configs[LogtoOidcConfigKey.RefreshTokenReuseInterval];
|
2022-04-21 16:13:59 +08:00
|
|
|
|
|
|
|
return Object.freeze({
|
2022-05-20 00:08:33 +08:00
|
|
|
cookieKeys,
|
2022-08-08 14:00:24 +08:00
|
|
|
privateJwks,
|
|
|
|
localJWKSet,
|
2022-07-05 18:01:49 +08:00
|
|
|
issuer,
|
2022-10-09 17:22:34 +08:00
|
|
|
refreshTokenReuseInterval,
|
2022-04-21 16:13:59 +08:00
|
|
|
defaultIdTokenTtl: 60 * 60,
|
|
|
|
defaultRefreshTokenTtl: 14 * 24 * 60 * 60,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export default loadOidcValues;
|