@@ -1580,6 +1580,113 @@ public void shouldNotAddAnyParamsIfNoSecretOrAssertion() throws Exception {
15801580 assertThat (response .getExpiresIn (), is (notNullValue ()));
15811581 }
15821582
1583+ @ Test
1584+ public void authorizeUrlWithPARShouldThrowWhenRequestUriNull () {
1585+ exception .expect (IllegalArgumentException .class );
1586+ exception .expectMessage ("'request uri' cannot be null!" );
1587+ api .authorizeUrlWithPAR (null );
1588+ }
1589+
1590+ @ Test
1591+ public void shouldBuildAuthorizeUrlWithPAR () {
1592+ AuthAPI api = AuthAPI .newBuilder ("domain.auth0.com" , CLIENT_ID , CLIENT_SECRET ).build ();
1593+ String url = api .authorizeUrlWithPAR ("urn:example:bwc4JK-ESC0w8acc191e-Y1LTC2" );
1594+ assertThat (url , is (notNullValue ()));
1595+ assertThat (url , isUrl ("https" , "domain.auth0.com" , "/authorize" ));
1596+
1597+ assertThat (url , hasQueryParameter ("request_uri" , "urn:example:bwc4JK-ESC0w8acc191e-Y1LTC2" ));
1598+ assertThat (url , hasQueryParameter ("client_id" , CLIENT_ID ));
1599+ }
1600+
1601+ @ Test
1602+ public void pushedAuthorizationRequestShouldThrowWhenRedirectUriIsNull () {
1603+ exception .expect (IllegalArgumentException .class );
1604+ exception .expectMessage ("'redirect uri' must be a valid URL!" );
1605+ api .pushedAuthorizationRequest (null , "code" , Collections .emptyMap ());
1606+ }
1607+
1608+ @ Test
1609+ public void pushedAuthorizationRequestShouldThrowWhenResponseTypeIsNull () {
1610+ exception .expect (IllegalArgumentException .class );
1611+ exception .expectMessage ("'response type' cannot be null!" );
1612+ api .pushedAuthorizationRequest ("https://domain.com/callback" , null , Collections .emptyMap ());
1613+ }
1614+
1615+ @ Test
1616+ public void shouldCreatePushedAuthorizationRequestWithNullAdditionalParams () throws Exception {
1617+ Request <PushedAuthorizationResponse > request = api .pushedAuthorizationRequest ("https://domain.com/callback" , "code" , null );
1618+ assertThat (request , is (notNullValue ()));
1619+
1620+ server .jsonResponse (PUSHED_AUTHORIZATION_RESPONSE , 200 );
1621+ PushedAuthorizationResponse response = request .execute ().getBody ();
1622+ RecordedRequest recordedRequest = server .takeRequest ();
1623+
1624+ assertThat (recordedRequest , hasMethodAndPath (HttpMethod .POST , "/oauth/par" ));
1625+ assertThat (recordedRequest , hasHeader ("Content-Type" , "application/x-www-form-urlencoded" ));
1626+
1627+ String body = readFromRequest (recordedRequest );
1628+ assertThat (body , containsString ("client_id=" + CLIENT_ID ));
1629+ assertThat (body , containsString ("redirect_uri=" + "https%3A%2F%2Fdomain.com%2Fcallback" ));
1630+ assertThat (body , containsString ("response_type=" + "code" ));
1631+ assertThat (body , containsString ("client_secret=" + CLIENT_SECRET ));
1632+
1633+ assertThat (response , is (notNullValue ()));
1634+ assertThat (response .getRequestURI (), not (emptyOrNullString ()));
1635+ assertThat (response .getExpiresIn (), notNullValue ());
1636+ }
1637+
1638+ @ Test
1639+ public void shouldCreatePushedAuthorizationRequestWithAdditionalParams () throws Exception {
1640+ Map <String , String > additionalParams = new HashMap <>();
1641+ additionalParams .put ("audience" , "aud" );
1642+ additionalParams .put ("connection" , "conn" );
1643+ Request <PushedAuthorizationResponse > request = api .pushedAuthorizationRequest ("https://domain.com/callback" , "code" , additionalParams );
1644+ assertThat (request , is (notNullValue ()));
1645+
1646+ server .jsonResponse (PUSHED_AUTHORIZATION_RESPONSE , 200 );
1647+ PushedAuthorizationResponse response = request .execute ().getBody ();
1648+ RecordedRequest recordedRequest = server .takeRequest ();
1649+
1650+ assertThat (recordedRequest , hasMethodAndPath (HttpMethod .POST , "/oauth/par" ));
1651+ assertThat (recordedRequest , hasHeader ("Content-Type" , "application/x-www-form-urlencoded" ));
1652+
1653+ String body = readFromRequest (recordedRequest );
1654+ assertThat (body , containsString ("client_id=" + CLIENT_ID ));
1655+ assertThat (body , containsString ("redirect_uri=" + "https%3A%2F%2Fdomain.com%2Fcallback" ));
1656+ assertThat (body , containsString ("response_type=" + "code" ));
1657+ assertThat (body , containsString ("client_secret=" + CLIENT_SECRET ));
1658+ assertThat (body , containsString ("audience=" + "aud" ));
1659+ assertThat (body , containsString ("connection=" + "conn" ));
1660+
1661+ assertThat (response , is (notNullValue ()));
1662+ assertThat (response .getRequestURI (), not (emptyOrNullString ()));
1663+ assertThat (response .getExpiresIn (), notNullValue ());
1664+ }
1665+
1666+ @ Test
1667+ public void shouldCreatePushedAuthorizationRequestWithoutSecret () throws Exception {
1668+ AuthAPI api = AuthAPI .newBuilder (server .getBaseUrl (), CLIENT_ID ).build ();
1669+ Request <PushedAuthorizationResponse > request = api .pushedAuthorizationRequest ("https://domain.com/callback" , "code" , null );
1670+ assertThat (request , is (notNullValue ()));
1671+
1672+ server .jsonResponse (PUSHED_AUTHORIZATION_RESPONSE , 200 );
1673+ PushedAuthorizationResponse response = request .execute ().getBody ();
1674+ RecordedRequest recordedRequest = server .takeRequest ();
1675+
1676+ assertThat (recordedRequest , hasMethodAndPath (HttpMethod .POST , "/oauth/par" ));
1677+ assertThat (recordedRequest , hasHeader ("Content-Type" , "application/x-www-form-urlencoded" ));
1678+
1679+ String body = readFromRequest (recordedRequest );
1680+ assertThat (body , containsString ("client_id=" + CLIENT_ID ));
1681+ assertThat (body , containsString ("redirect_uri=" + "https%3A%2F%2Fdomain.com%2Fcallback" ));
1682+ assertThat (body , containsString ("response_type=" + "code" ));
1683+ assertThat (body , not (containsString ("client_secret" )));
1684+
1685+ assertThat (response , is (notNullValue ()));
1686+ assertThat (response .getRequestURI (), not (emptyOrNullString ()));
1687+ assertThat (response .getExpiresIn (), notNullValue ());
1688+ }
1689+
15831690 static class TestAssertionSigner implements ClientAssertionSigner {
15841691
15851692 private final String token ;
0 commit comments