@@ -26,6 +26,27 @@ 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
+ 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
+
29
50
export type CognitoUserInfo = {
30
51
username : string ;
31
52
email : string ;
@@ -68,3 +89,30 @@ export const getCorbadoConnectToken = async (connectTokenType: string, connectTo
68
89
69
90
return out . secret ;
70
91
} ;
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