@@ -26,6 +26,27 @@ export const verifyAmplifyToken = async (idToken: string): Promise<TokenData> =>
2626 return { displayName, identifier } ;
2727} ;
2828
29+ export const verifyAmplifyTokenExternal = async ( idToken : string ) : Promise < TokenData > => {
30+ const verifier = CognitoJwtVerifier . create ( {
31+ userPoolId : process . env . AWS_COGNITO_USER_POOL_ID_EXTERNAL ! ,
32+ tokenUse : 'id' ,
33+ clientId : process . env . AWS_COGNITO_CLIENT_ID_EXTERNAL ! ,
34+ } ) ;
35+
36+ console . log (
37+ 'verifying token with external verifier' ,
38+ idToken ,
39+ process . env . AWS_COGNITO_USER_POOL_ID_EXTERNAL ,
40+ process . env . AWS_COGNITO_CLIENT_ID_EXTERNAL ,
41+ ) ;
42+
43+ const verifiedToken = await verifier . verify ( idToken ) ;
44+ const displayName : string = verifiedToken . email as string ;
45+ const identifier = verifiedToken [ 'cognito:username' ] ;
46+
47+ return { displayName, identifier } ;
48+ } ;
49+
2950export type CognitoUserInfo = {
3051 username : string ;
3152 email : string ;
@@ -68,3 +89,30 @@ export const getCorbadoConnectToken = async (connectTokenType: string, connectTo
6889
6990 return out . secret ;
7091} ;
92+
93+ export const getCorbadoConnectTokenExternal = async (
94+ connectTokenType : string ,
95+ connectTokenData : any ,
96+ ) : Promise < string > => {
97+ const payload = {
98+ type : connectTokenType ,
99+ data : connectTokenData ,
100+ } ;
101+
102+ const body = JSON . stringify ( payload ) ;
103+
104+ const url = `${ process . env . CORBADO_BACKEND_API_URL_EXTERNAL } /v2/connectTokens` ;
105+ const response = await fetch ( url , {
106+ method : 'POST' ,
107+ headers : {
108+ Authorization : `Basic ${ process . env . CORBADO_BACKEND_API_BASIC_AUTH_EXTERNAL } ` ,
109+ 'Content-Type' : 'application/json' ,
110+ } ,
111+ cache : 'no-cache' ,
112+ body : body ,
113+ } ) ;
114+
115+ const out = await response . json ( ) ;
116+
117+ return out . secret ;
118+ } ;
0 commit comments