@@ -2009,6 +2009,127 @@ public void shouldThrowWhenCreatePushedAuthorizationJarRequestWithInvalidAuthDet
20092009 assertThat (e .getCause (), instanceOf (JsonProcessingException .class ));
20102010 }
20112011
2012+ @ Test
2013+ public void authorizeBackChannelWhenScopeIsNull () {
2014+ verifyThrows (IllegalArgumentException .class ,
2015+ () -> api .authorizeBackChannel (null , "This is binding message" , getLoginHint ()),
2016+ "'scope' cannot be null!" );
2017+ }
2018+
2019+ @ Test
2020+ public void authorizeBackChannelWhenBindingMessageIsNull () {
2021+ verifyThrows (IllegalArgumentException .class ,
2022+ () -> api .authorizeBackChannel ("openid" , null , getLoginHint ()),
2023+ "'binding message' cannot be null!" );
2024+ }
2025+
2026+ @ Test
2027+ public void authorizeBackChannelWhenLoginHintIsNull () {
2028+ verifyThrows (IllegalArgumentException .class ,
2029+ () -> api .authorizeBackChannel ("openid" , "This is binding message" , null ),
2030+ "'login hint' cannot be null!" );
2031+ }
2032+
2033+ @ Test
2034+ public void authorizeBackChannel () throws Exception {
2035+ Request <BackChannelAuthorizeResponse > request = api .authorizeBackChannel ("openid" , "This is binding message" , getLoginHint ());
2036+ assertThat (request , is (notNullValue ()));
2037+
2038+ server .jsonResponse (BACK_CHANNEL_AUTHORIZE_RESPONSE , 200 );
2039+ BackChannelAuthorizeResponse response = request .execute ().getBody ();
2040+ RecordedRequest recordedRequest = server .takeRequest ();
2041+
2042+ assertThat (recordedRequest , hasMethodAndPath (HttpMethod .POST , "/bc-authorize" ));
2043+ assertThat (recordedRequest , hasHeader ("Content-Type" , "application/x-www-form-urlencoded" ));
2044+
2045+ String body = URLDecoder .decode (readFromRequest (recordedRequest ), StandardCharsets .UTF_8 .name ());
2046+ assertThat (body , containsString ("scope=" + "openid" ));
2047+ assertThat (body , containsString ("client_id=" + CLIENT_ID ));
2048+ assertThat (body , containsString ("client_secret=" + CLIENT_SECRET ));
2049+ assertThat (body , containsString ("binding_message=This is binding message" ));
2050+ assertThat (body , containsString ("login_hint={\" sub\" :\" auth0|user1\" ,\" format\" :\" format1\" ,\" iss\" :\" https://auth0.com\" }" ));
2051+
2052+ assertThat (response , is (notNullValue ()));
2053+ assertThat (response .getAuthReqId (), not (emptyOrNullString ()));
2054+ assertThat (response .getExpiresIn (), notNullValue ());
2055+ assertThat (response .getInterval (), notNullValue ());
2056+ }
2057+
2058+ @ Test
2059+ public void authorizeBackChannelWithAudienceAndRequestExpiry () throws Exception {
2060+ Request <BackChannelAuthorizeResponse > request = api .authorizeBackChannel ("openid" , "This is binding message" , getLoginHint (), "https://api.example.com" , 300 );
2061+ assertThat (request , is (notNullValue ()));
2062+
2063+ server .jsonResponse (BACK_CHANNEL_AUTHORIZE_RESPONSE , 200 );
2064+ BackChannelAuthorizeResponse response = request .execute ().getBody ();
2065+ RecordedRequest recordedRequest = server .takeRequest ();
2066+
2067+ assertThat (recordedRequest , hasMethodAndPath (HttpMethod .POST , "/bc-authorize" ));
2068+ assertThat (recordedRequest , hasHeader ("Content-Type" , "application/x-www-form-urlencoded" ));
2069+
2070+ String body = URLDecoder .decode (readFromRequest (recordedRequest ), StandardCharsets .UTF_8 .name ());
2071+ assertThat (body , containsString ("scope=" + "openid" ));
2072+ assertThat (body , containsString ("client_id=" + CLIENT_ID ));
2073+ assertThat (body , containsString ("client_secret=" + CLIENT_SECRET ));
2074+ assertThat (body , containsString ("binding_message=This is binding message" ));
2075+ assertThat (body , containsString ("login_hint={\" sub\" :\" auth0|user1\" ,\" format\" :\" format1\" ,\" iss\" :\" https://auth0.com\" }" ));
2076+ assertThat (body , containsString ("request_expiry=" + 300 ));
2077+ assertThat (body , containsString ("audience=" + "https://api.example.com" ));
2078+
2079+ assertThat (response , is (notNullValue ()));
2080+ assertThat (response .getAuthReqId (), not (emptyOrNullString ()));
2081+ assertThat (response .getExpiresIn (), notNullValue ());
2082+ assertThat (response .getInterval (), notNullValue ());
2083+ }
2084+
2085+ private Map <String , Object > getLoginHint () {
2086+ Map <String , Object > loginHint = new HashMap <>();
2087+ loginHint .put ("format" , "format1" );
2088+ loginHint .put ("iss" , "https://auth0.com" );
2089+ loginHint .put ("sub" , "auth0|user1" );
2090+ return loginHint ;
2091+ }
2092+
2093+ @ Test
2094+ public void getBackChannelLoginStatusWhenAuthReqIdIsNull () {
2095+ verifyThrows (IllegalArgumentException .class ,
2096+ () -> api .getBackChannelLoginStatus (null , "ciba" ),
2097+ "'auth req id' cannot be null!" );
2098+ }
2099+
2100+ @ Test
2101+ public void getBackChannelLoginStatusWhenGrantTypeIsNull () {
2102+ verifyThrows (IllegalArgumentException .class ,
2103+ () -> api .getBackChannelLoginStatus ("red_id_1" , null ),
2104+ "'grant type' cannot be null!" );
2105+ }
2106+
2107+ @ Test
2108+ public void getBackChannelLoginStatus () throws Exception {
2109+ Request <BackChannelTokenResponse > request = api .getBackChannelLoginStatus ("red_id_1" , "ciba" );
2110+ assertThat (request , is (notNullValue ()));
2111+
2112+ server .jsonResponse (BACK_CHANNEL_LOGIN_STATUS_RESPONSE , 200 );
2113+ BackChannelTokenResponse response = request .execute ().getBody ();
2114+ RecordedRequest recordedRequest = server .takeRequest ();
2115+
2116+ assertThat (recordedRequest , hasMethodAndPath (HttpMethod .POST , "/oauth/token" ));
2117+ assertThat (recordedRequest , hasHeader ("Content-Type" , "application/x-www-form-urlencoded" ));
2118+
2119+ String body = URLDecoder .decode (readFromRequest (recordedRequest ), StandardCharsets .UTF_8 .name ());
2120+ assertThat (body , containsString ("client_id=" + CLIENT_ID ));
2121+ assertThat (body , containsString ("client_secret=" + CLIENT_SECRET ));
2122+ assertThat (body , containsString ("auth_req_id=red_id_1" ));
2123+ assertThat (body , containsString ("grant_type=ciba" ));
2124+
2125+ assertThat (response , is (notNullValue ()));
2126+ assertThat (response .getAccessToken (), not (emptyOrNullString ()));
2127+ assertThat (response .getIdToken (), not (emptyOrNullString ()));
2128+ assertThat (response .getExpiresIn (), notNullValue ());
2129+ assertThat (response .getScope (), not (emptyOrNullString ()));
2130+ }
2131+
2132+
20122133 private Map <String , String > getQueryMap (String input ) {
20132134 String [] params = input .split ("&" );
20142135
0 commit comments