@@ -26,6 +26,20 @@ export const verifyAmplifyToken = async (idToken: string): Promise<TokenData> =>
26
26
return { displayName, identifier } ;
27
27
} ;
28
28
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
+ const verifiedToken = await verifier . verify ( idToken ) ;
37
+ const displayName : string = verifiedToken . email as string ;
38
+ const identifier = verifiedToken [ 'cognito:username' ] ;
39
+
40
+ return { displayName, identifier } ;
41
+ } ;
42
+
29
43
export type CognitoUserInfo = {
30
44
username : string ;
31
45
email : string ;
@@ -68,3 +82,30 @@ export const getCorbadoConnectToken = async (connectTokenType: string, connectTo
68
82
69
83
return out . secret ;
70
84
} ;
85
+
86
+ export const getCorbadoConnectTokenExternal = async (
87
+ connectTokenType : string ,
88
+ connectTokenData : any ,
89
+ ) : Promise < string > => {
90
+ const payload = {
91
+ type : connectTokenType ,
92
+ data : connectTokenData ,
93
+ } ;
94
+
95
+ const body = JSON . stringify ( payload ) ;
96
+
97
+ const url = `${ process . env . CORBADO_BACKEND_API_URL_EXTERNAL } /v2/connectTokens` ;
98
+ const response = await fetch ( url , {
99
+ method : 'POST' ,
100
+ headers : {
101
+ Authorization : `Basic ${ process . env . CORBADO_BACKEND_API_BASIC_AUTH_EXTERNAL } ` ,
102
+ 'Content-Type' : 'application/json' ,
103
+ } ,
104
+ cache : 'no-cache' ,
105
+ body : body ,
106
+ } ) ;
107
+
108
+ const out = await response . json ( ) ;
109
+
110
+ return out . secret ;
111
+ } ;
0 commit comments