@@ -1035,6 +1035,82 @@ public void shouldCreateTokenExchangeRequestWithClientAssertion() throws Excepti
10351035 assertThat (response .getAccessToken (), not (emptyOrNullString ()));
10361036 }
10371037
1038+ // Token Vault - Federated Connection Access Token
1039+
1040+ @ Test
1041+ public void shouldThrowOnGetTokenForConnectionWithNullConnection () {
1042+ verifyThrows (
1043+ IllegalArgumentException .class ,
1044+ () -> api .getTokenForConnection (null , "test-refresh-token" , null ),
1045+ "'connection' cannot be null!" );
1046+ }
1047+
1048+ @ Test
1049+ public void shouldThrowOnGetTokenForConnectionWithNullRefreshToken () {
1050+ verifyThrows (
1051+ IllegalArgumentException .class ,
1052+ () -> api .getTokenForConnection ("google-oauth2" , null , null ),
1053+ "'refresh token' cannot be null!" );
1054+ }
1055+
1056+ @ Test
1057+ public void shouldCreateGetTokenForConnectionRequest () throws Exception {
1058+ TokenRequest request = api .getTokenForConnection ("google-oauth2" , "test-refresh-token" , null );
1059+ assertThat (request , is (notNullValue ()));
1060+
1061+ server .jsonResponse (AUTH_TOKENS , 200 );
1062+ TokenHolder response = request .execute ().getBody ();
1063+ RecordedRequest recordedRequest = server .takeRequest ();
1064+
1065+ assertThat (recordedRequest , hasMethodAndPath (HttpMethod .POST , "/oauth/token" ));
1066+ assertThat (recordedRequest , hasHeader ("Content-Type" , "application/json" ));
1067+
1068+ Map <String , Object > body = bodyFromRequest (recordedRequest );
1069+ assertThat (
1070+ body ,
1071+ hasEntry (
1072+ "grant_type" ,
1073+ "urn:auth0:params:oauth:grant-type:token-exchange:federated-connection-access-token" ));
1074+ assertThat (body , hasEntry ("client_id" , CLIENT_ID ));
1075+ assertThat (body , hasEntry ("client_secret" , CLIENT_SECRET ));
1076+ assertThat (body , hasEntry ("subject_token" , "test-refresh-token" ));
1077+ assertThat (body , hasEntry ("subject_token_type" , "urn:ietf:params:oauth:token-type:refresh_token" ));
1078+ assertThat (
1079+ body ,
1080+ hasEntry (
1081+ "requested_token_type" , "http://auth0.com/oauth/token-type/federated-connection-access-token" ));
1082+ assertThat (body , hasEntry ("connection" , "google-oauth2" ));
1083+ assertThat (body , not (hasKey ("login_hint" )));
1084+
1085+ assertThat (response , is (notNullValue ()));
1086+ assertThat (response .getAccessToken (), not (emptyOrNullString ()));
1087+ }
1088+
1089+ @ Test
1090+ public void shouldCreateGetTokenForConnectionRequestWithLoginHint () throws Exception {
1091+ TokenRequest request = api .getTokenForConnection ("google-oauth2" , "test-refresh-token" , "google-user-id" );
1092+ assertThat (request , is (notNullValue ()));
1093+
1094+ server .jsonResponse (AUTH_TOKENS , 200 );
1095+ TokenHolder response = request .execute ().getBody ();
1096+ RecordedRequest recordedRequest = server .takeRequest ();
1097+
1098+ Map <String , Object > body = bodyFromRequest (recordedRequest );
1099+ assertThat (body , hasEntry ("connection" , "google-oauth2" ));
1100+ assertThat (body , hasEntry ("login_hint" , "google-user-id" ));
1101+
1102+ assertThat (response , is (notNullValue ()));
1103+ assertThat (response .getAccessToken (), not (emptyOrNullString ()));
1104+ }
1105+
1106+ @ Test
1107+ public void getTokenForConnectionRequiresClientAuthentication () {
1108+ verifyThrows (
1109+ IllegalStateException .class ,
1110+ () -> apiNoClientAuthentication .getTokenForConnection ("google-oauth2" , "test-refresh-token" , null ),
1111+ "A client secret or client assertion signing key is required for this operation" );
1112+ }
1113+
10381114 // Login with Passwordless
10391115
10401116 @ Test
0 commit comments