@@ -44,10 +44,9 @@ app.get(`${API_PREFIX}/login`, async (c) => {
44
44
45
45
app . get ( `${ API_PREFIX } /callback` , async ( c ) => {
46
46
const accessToken = await getOIDCAccessToken ( c . req . query ( "code" ) ! ) ;
47
- console . log ( accessToken ) ;
47
+ const data = await getUserinfo ( accessToken ) ;
48
48
49
-
50
- const [ _header , _payload , _signature ] = decode ( accessToken ) ;
49
+ const [ _header , _payload , _signature ] = decode ( data ) ;
51
50
console . debug ( _payload ) ;
52
51
const { preferred_username : username , groups : oidc_groups } = _payload as {
53
52
preferred_username : string ;
@@ -74,7 +73,11 @@ app.get(`${API_PREFIX}/callback`, async (c) => {
74
73
return c . redirect ( "/" ) ;
75
74
} ) ;
76
75
77
- let oidcConfig : { authorization_endpoint : string ; token_endpoint : string } ;
76
+ let oidcConfig : {
77
+ authorization_endpoint : string ;
78
+ token_endpoint : string ;
79
+ userinfo_endpoint : string ;
80
+ } ;
78
81
async function getOIDCConfig ( ) {
79
82
if ( ! oidcConfig ) {
80
83
const resp = await fetch ( OIDC_CONFIG_URL ) ;
@@ -101,6 +104,14 @@ async function getOIDCAccessToken(code: string) {
101
104
return json . access_token as string ;
102
105
}
103
106
107
+ async function getUserinfo ( accessToken : string ) {
108
+ const config = await getOIDCConfig ( ) ;
109
+ const resp = await fetch ( config . userinfo_endpoint , {
110
+ headers : { Authorization : `Bearer ${ accessToken } ` } ,
111
+ } ) ;
112
+ return await resp . json ( ) ;
113
+ }
114
+
104
115
async function createToken ( ) {
105
116
const resp = await fetch ( `${ SFTPGO_WEB_URL } /api/v2/token` , {
106
117
headers : { Authorization : `Basic ${ SFTPGO_ADMIN_BASICAUTH } ` } ,
0 commit comments