@@ -2272,6 +2272,90 @@ public class AuthenticationAPIClientTest {
22722272 assertThat(body, Matchers .hasEntry(" token" , " refreshToken" ))
22732273 }
22742274
2275+ @Test
2276+ public fun shouldCustomTokenExchange () {
2277+ mockAPI.willReturnSuccessfulLogin()
2278+ val callback = MockAuthenticationCallback <Credentials >()
2279+ client.customTokenExchange( " subject-token-type" ," subject-token" )
2280+ .setScope(" openid profile email" )
2281+ .start(callback)
2282+ ShadowLooper .idleMainLooper()
2283+ val request = mockAPI.takeRequest()
2284+ assertThat(
2285+ request.getHeader(" Accept-Language" ), Matchers .`is `(
2286+ defaultLocale
2287+ )
2288+ )
2289+ assertThat(request.path, Matchers .equalTo(" /oauth/token" ))
2290+ val body = bodyFromRequest<String >(request)
2291+ assertThat(body, Matchers .hasEntry(" client_id" , CLIENT_ID ))
2292+ assertThat(
2293+ body,
2294+ Matchers .hasEntry(" grant_type" , ParameterBuilder .GRANT_TYPE_TOKEN_EXCHANGE )
2295+ )
2296+ assertThat(body, Matchers .hasEntry(" subject_token" , " subject-token" ))
2297+ assertThat(body, Matchers .hasEntry(" subject_token_type" , " subject-token-type" ))
2298+ assertThat(body, Matchers .hasEntry(" scope" , " openid profile email" ))
2299+ assertThat(
2300+ callback, AuthenticationCallbackMatcher .hasPayloadOfType(
2301+ Credentials ::class .java
2302+ )
2303+ )
2304+ }
2305+
2306+ @Test
2307+ public fun shouldCustomTokenExchangeSync () {
2308+ mockAPI.willReturnSuccessfulLogin()
2309+ val credentials = client
2310+ .customTokenExchange(" subject-token-type" , " subject-token" )
2311+ .setScope(" openid profile email" )
2312+ .execute()
2313+ val request = mockAPI.takeRequest()
2314+ assertThat(
2315+ request.getHeader(" Accept-Language" ), Matchers .`is `(
2316+ defaultLocale
2317+ )
2318+ )
2319+ assertThat(request.path, Matchers .equalTo(" /oauth/token" ))
2320+ val body = bodyFromRequest<String >(request)
2321+ assertThat(body, Matchers .hasEntry(" client_id" , CLIENT_ID ))
2322+ assertThat(
2323+ body,
2324+ Matchers .hasEntry(" grant_type" , ParameterBuilder .GRANT_TYPE_TOKEN_EXCHANGE )
2325+ )
2326+ assertThat(body, Matchers .hasEntry(" subject_token" , " subject-token" ))
2327+ assertThat(body, Matchers .hasEntry(" subject_token_type" , " subject-token-type" ))
2328+ assertThat(body, Matchers .hasEntry(" scope" , " openid profile email" ))
2329+ assertThat(credentials, Matchers .`is `(Matchers .notNullValue()))
2330+ }
2331+
2332+ @Test
2333+ @ExperimentalCoroutinesApi
2334+ public fun shouldAwaitCustomTokenExchnage (): Unit = runTest {
2335+ mockAPI.willReturnSuccessfulLogin()
2336+ val credentials = client
2337+ .customTokenExchange(" subject-token-type" , " subject-token" )
2338+ .setScope(" openid profile email" )
2339+ .await()
2340+ val request = mockAPI.takeRequest()
2341+ assertThat(
2342+ request.getHeader(" Accept-Language" ), Matchers .`is `(
2343+ defaultLocale
2344+ )
2345+ )
2346+ assertThat(request.path, Matchers .equalTo(" /oauth/token" ))
2347+ val body = bodyFromRequest<String >(request)
2348+ assertThat(body, Matchers .hasEntry(" client_id" , CLIENT_ID ))
2349+ assertThat(
2350+ body,
2351+ Matchers .hasEntry(" grant_type" , ParameterBuilder .GRANT_TYPE_TOKEN_EXCHANGE )
2352+ )
2353+ assertThat(body, Matchers .hasEntry(" subject_token" , " subject-token" ))
2354+ assertThat(body, Matchers .hasEntry(" subject_token_type" , " subject-token-type" ))
2355+ assertThat(body, Matchers .hasEntry(" scope" , " openid profile email" ))
2356+ assertThat(credentials, Matchers .`is `(Matchers .notNullValue()))
2357+ }
2358+
22752359 @Test
22762360 public fun shouldRenewAuthWithOAuthToken () {
22772361 val auth0 = auth0
0 commit comments