@@ -64,7 +64,8 @@ class OAuth2AuthCredentialsViewModel(application: Application) : BaseAndroidView
64
64
return @launch
65
65
}
66
66
67
- val claims = validateTokenAndGetClaims(response.data?.idToken ? : " " )
67
+ val claims = validateTokenAndGetClaims(response.data?.idToken ? : " " , authRequest
68
+ .clientId, jwks = JWKS_MICROSOFT )
68
69
val email: String? = claims.getClaimValueAsString(CLAIM_EMAIL )?.toLowerCase(Locale .US )
69
70
val displayName: String? = claims.getClaimValueAsString(CLAIM_NAME )
70
71
@@ -85,20 +86,23 @@ class OAuth2AuthCredentialsViewModel(application: Application) : BaseAndroidView
85
86
}
86
87
}
87
88
88
- private suspend fun validateTokenAndGetClaims (idToken : String ): JwtClaims =
89
+ private suspend fun validateTokenAndGetClaims (idToken : String , clientId : String , jwks : String ):
90
+ JwtClaims =
89
91
withContext(Dispatchers .IO ) {
90
- // https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration
91
- val httpsJkws = HttpsJwks (" https://login.microsoftonline.com/common/discovery/v2.0/keys" )
92
+ val httpsJkws = HttpsJwks (jwks)
92
93
val httpsJwksKeyResolver = HttpsJwksVerificationKeyResolver (httpsJkws)
93
94
val jwtConsumer = JwtConsumerBuilder ()
94
95
.setVerificationKeyResolver(httpsJwksKeyResolver)
95
- .setExpectedAudience(" 3be51534-5f76-4970-9a34-40ef197aa018 " )
96
+ .setExpectedAudience(clientId )
96
97
.build()
97
98
return @withContext jwtConsumer.processToClaims(idToken)
98
99
}
99
100
100
101
companion object {
101
102
private const val CLAIM_EMAIL = " email"
102
103
private const val CLAIM_NAME = " name"
104
+
105
+ // https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration
106
+ private const val JWKS_MICROSOFT = " https://login.microsoftonline.com/common/discovery/v2.0/keys"
103
107
}
104
108
}
0 commit comments