oltu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r1732995 - in /oltu/trunk/oauth-2.0: authzserver/src/main/java/org/apache/oltu/oauth2/as/response/ authzserver/src/test/java/org/apache/oltu/oauth2/as/response/ client/src/main/java/org/apache/oltu/oauth2/client/response/ client/src/test/ja...
Date Tue, 01 Mar 2016 05:37:36 GMT
Author: stein
Date: Tue Mar  1 05:37:36 2016
New Revision: 1732995

URL: http://svn.apache.org/viewvc?rev=1732995&view=rev
Log:
OLTU-29 Add token type to OAuth responses. Thanks Sam Gorial for the patch!

Modified:
    oltu/trunk/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/response/OAuthASResponse.java
    oltu/trunk/oauth-2.0/authzserver/src/test/java/org/apache/oltu/oauth2/as/response/OAuthASResponseTest.java
    oltu/trunk/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/GitHubTokenResponse.java
    oltu/trunk/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/OAuthAccessTokenResponse.java
    oltu/trunk/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/OAuthJSONAccessTokenResponse.java
    oltu/trunk/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/response/OAuthJSONAccessTokenResponseTest.java
    oltu/trunk/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/utils/TestUtils.java
    oltu/trunk/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/token/BasicOAuthToken.java
    oltu/trunk/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/token/OAuthToken.java
    oltu/trunk/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints/AuthzEndpoint.java
    oltu/trunk/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints/TokenEndpoint.java

Modified: oltu/trunk/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/response/OAuthASResponse.java
URL: http://svn.apache.org/viewvc/oltu/trunk/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/response/OAuthASResponse.java?rev=1732995&r1=1732994&r2=1732995&view=diff
==============================================================================
--- oltu/trunk/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/response/OAuthASResponse.java
(original)
+++ oltu/trunk/oauth-2.0/authzserver/src/main/java/org/apache/oltu/oauth2/as/response/OAuthASResponse.java
Tue Mar  1 05:37:36 2016
@@ -72,6 +72,11 @@ public class OAuthASResponse extends OAu
             return this;
         }
 
+        public OAuthAuthorizationResponseBuilder setTokenType(String tokenType) {
+            this.parameters.put(OAuth.OAUTH_TOKEN_TYPE, tokenType);
+            return this;
+        }
+
         public OAuthAuthorizationResponseBuilder setExpiresIn(String expiresIn) {
             this.parameters.put(OAuth.OAUTH_EXPIRES_IN, expiresIn == null ? null : Long.valueOf(expiresIn));
             return this;

Modified: oltu/trunk/oauth-2.0/authzserver/src/test/java/org/apache/oltu/oauth2/as/response/OAuthASResponseTest.java
URL: http://svn.apache.org/viewvc/oltu/trunk/oauth-2.0/authzserver/src/test/java/org/apache/oltu/oauth2/as/response/OAuthASResponseTest.java?rev=1732995&r1=1732994&r2=1732995&view=diff
==============================================================================
--- oltu/trunk/oauth-2.0/authzserver/src/test/java/org/apache/oltu/oauth2/as/response/OAuthASResponseTest.java
(original)
+++ oltu/trunk/oauth-2.0/authzserver/src/test/java/org/apache/oltu/oauth2/as/response/OAuthASResponseTest.java
Tue Mar  1 05:37:36 2016
@@ -27,7 +27,6 @@ import static org.easymock.EasyMock.repl
 
 import javax.servlet.http.HttpServletRequest;
 
-import org.apache.oltu.oauth2.as.response.OAuthASResponse;
 import org.apache.oltu.oauth2.common.OAuth;
 import org.apache.oltu.oauth2.common.error.OAuthError;
 import org.apache.oltu.oauth2.common.exception.OAuthProblemException;
@@ -82,29 +81,29 @@ public class OAuthASResponseTest {
         HttpServletRequest request = createMock(HttpServletRequest.class);
         expect(request.getParameter(OAuth.OAUTH_STATE)).andStubReturn("ok");
         replay(request);
-        OAuthResponse oAuthResponse = OAuthASResponse.authorizationResponse(request,200)
-        .location("http://www.example.com")
-        .setAccessToken("access_111")
-        .setExpiresIn("400")
-        .setParam("testValue", "value2")
-        .buildQueryMessage();
+        OAuthResponse oAuthResponse = OAuthASResponse.authorizationResponse(request, 200)
+                .location("http://www.example.com")
+                .setAccessToken("access_111")
+                .setTokenType("bearer")
+                .setExpiresIn("400")
+                .setParam("testValue", "value2")
+                .buildQueryMessage();
 
         String url = oAuthResponse.getLocationUri();
-        Assert.assertEquals("http://www.example.com#testValue=value2&state=ok&expires_in=400&access_token=access_111",
url);
+        Assert.assertEquals("http://www.example.com#testValue=value2&state=ok&expires_in=400&token_type=bearer&access_token=access_111",
url);
         Assert.assertEquals(200, oAuthResponse.getResponseStatus());
     }
 
-
     @Test
     public void testTokenResponse() throws Exception {
 
         OAuthResponse oAuthResponse = OAuthASResponse.tokenResponse(200).setAccessToken("access_token")
-            .setExpiresIn("200").setRefreshToken("refresh_token2")
+            .setTokenType("bearer").setExpiresIn("200").setRefreshToken("refresh_token2")
             .buildBodyMessage();
 
         String body = oAuthResponse.getBody();
         Assert.assertEquals(
-            "expires_in=200&refresh_token=refresh_token2&access_token=access_token",
+            "expires_in=200&token_type=bearer&refresh_token=refresh_token2&access_token=access_token",
             body);
 
     }
@@ -113,12 +112,12 @@ public class OAuthASResponseTest {
     public void testTokenResponseAdditionalParam() throws Exception {
 
         OAuthResponse oAuthResponse = OAuthASResponse.tokenResponse(200).setAccessToken("access_token")
-            .setExpiresIn("200").setRefreshToken("refresh_token2").setParam("some_param",
"new_param")
+            .setTokenType("bearer").setExpiresIn("200").setRefreshToken("refresh_token2").setParam("some_param",
"new_param")
             .buildBodyMessage();
 
         String body = oAuthResponse.getBody();
         Assert.assertEquals(
-            "some_param=new_param&expires_in=200&refresh_token=refresh_token2&access_token=access_token",
+            "some_param=new_param&expires_in=200&token_type=bearer&refresh_token=refresh_token2&access_token=access_token",
             body);
 
     }

Modified: oltu/trunk/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/GitHubTokenResponse.java
URL: http://svn.apache.org/viewvc/oltu/trunk/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/GitHubTokenResponse.java?rev=1732995&r1=1732994&r2=1732995&view=diff
==============================================================================
--- oltu/trunk/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/GitHubTokenResponse.java
(original)
+++ oltu/trunk/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/GitHubTokenResponse.java
Tue Mar  1 05:37:36 2016
@@ -26,7 +26,6 @@ import org.apache.oltu.oauth2.common.tok
 import org.apache.oltu.oauth2.common.token.OAuthToken;
 import org.apache.oltu.oauth2.common.utils.OAuthUtils;
 
-
 /**
  *
  *
@@ -34,11 +33,15 @@ import org.apache.oltu.oauth2.common.uti
  */
 public class GitHubTokenResponse extends OAuthAccessTokenResponse {
 
-
     public String getAccessToken() {
         return getParam(OAuth.OAUTH_ACCESS_TOKEN);
     }
 
+    @Override
+    public String getTokenType() {
+    	return getParam(OAuth.OAUTH_TOKEN_TYPE);
+    }
+
     public Long getExpiresIn() {
         String value = getParam(OAuth.OAUTH_EXPIRES_IN);
         return value == null? null: Long.valueOf(value);
@@ -53,7 +56,7 @@ public class GitHubTokenResponse extends
     }
 
     public OAuthToken getOAuthToken() {
-        return new BasicOAuthToken(getAccessToken(), getExpiresIn(), getRefreshToken(), getScope());
+        return new BasicOAuthToken(getAccessToken(), getTokenType(), getExpiresIn(), getRefreshToken(),
getScope());
     }
 
     protected void setBody(String body) {
@@ -68,6 +71,4 @@ public class GitHubTokenResponse extends
     protected void setResponseCode(int code) {
         this.responseCode = code;
     }
-
-
 }

Modified: oltu/trunk/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/OAuthAccessTokenResponse.java
URL: http://svn.apache.org/viewvc/oltu/trunk/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/OAuthAccessTokenResponse.java?rev=1732995&r1=1732994&r2=1732995&view=diff
==============================================================================
--- oltu/trunk/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/OAuthAccessTokenResponse.java
(original)
+++ oltu/trunk/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/OAuthAccessTokenResponse.java
Tue Mar  1 05:37:36 2016
@@ -41,6 +41,8 @@ public abstract class OAuthAccessTokenRe
 
     public abstract String getAccessToken();
 
+    public abstract String getTokenType();
+    
     public abstract Long getExpiresIn();
 
     public abstract String getRefreshToken();

Modified: oltu/trunk/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/OAuthJSONAccessTokenResponse.java
URL: http://svn.apache.org/viewvc/oltu/trunk/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/OAuthJSONAccessTokenResponse.java?rev=1732995&r1=1732994&r2=1732995&view=diff
==============================================================================
--- oltu/trunk/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/OAuthJSONAccessTokenResponse.java
(original)
+++ oltu/trunk/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/response/OAuthJSONAccessTokenResponse.java
Tue Mar  1 05:37:36 2016
@@ -45,6 +45,11 @@ public class OAuthJSONAccessTokenRespons
     }
 
     @Override
+    public String getTokenType() {
+        return getParam(OAuth.OAUTH_TOKEN_TYPE);
+    }
+
+    @Override
     public Long getExpiresIn() {
         String value = getParam(OAuth.OAUTH_EXPIRES_IN);
         return value == null? null: Long.valueOf(value);
@@ -55,7 +60,7 @@ public class OAuthJSONAccessTokenRespons
     }
 
     public OAuthToken getOAuthToken() {
-        return new BasicOAuthToken(getAccessToken(), getExpiresIn(), getRefreshToken(), getScope());
+        return new BasicOAuthToken(getAccessToken(), getTokenType(), getExpiresIn(), getRefreshToken(),
getScope());
     }
 
     public String getRefreshToken() {

Modified: oltu/trunk/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/response/OAuthJSONAccessTokenResponseTest.java
URL: http://svn.apache.org/viewvc/oltu/trunk/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/response/OAuthJSONAccessTokenResponseTest.java?rev=1732995&r1=1732994&r2=1732995&view=diff
==============================================================================
--- oltu/trunk/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/response/OAuthJSONAccessTokenResponseTest.java
(original)
+++ oltu/trunk/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/response/OAuthJSONAccessTokenResponseTest.java
Tue Mar  1 05:37:36 2016
@@ -42,7 +42,6 @@ public class OAuthJSONAccessTokenRespons
 
     @Test
     public void testGetAccessToken() throws Exception {
-        logger.info("Running test: testGetAccessToken " + this.getClass().getName());
         OAuthJSONAccessTokenResponse r = null;
         try {
             r = new OAuthJSONAccessTokenResponse();
@@ -65,9 +64,8 @@ public class OAuthJSONAccessTokenRespons
     }
 
     @Test
-    public void testGetExpiresIn() throws Exception {
+    public void testGetTokenType() throws Exception {
         OAuthJSONAccessTokenResponse r = null;
-
         try {
             r = new OAuthJSONAccessTokenResponse();
             r.init(TestUtils.VALID_JSON_RESPONSE,
@@ -76,10 +74,10 @@ public class OAuthJSONAccessTokenRespons
             fail("Exception not expected");
         }
 
-        Assert.assertEquals(TestUtils.EXPIRES_IN, r.getExpiresIn());
+        Assert.assertEquals(TestUtils.TOKEN_TYPE, r.getTokenType());
 
         try {
-            new OAuthJSONAccessTokenResponse();
+            r = new OAuthJSONAccessTokenResponse();
             r.init(TestUtils.ERROR_JSON_BODY,
                 OAuth.ContentType.JSON, 200);
             fail("Exception expected");
@@ -89,6 +87,23 @@ public class OAuthJSONAccessTokenRespons
     }
 
     @Test
+    public void testGetExpiresIn() throws Exception {
+        OAuthJSONAccessTokenResponse r = null;
+
+        try {
+            r = new OAuthJSONAccessTokenResponse();
+            r.init(TestUtils.VALID_JSON_RESPONSE,
+                OAuth.ContentType.JSON, 200);
+        } catch (OAuthProblemException e) {
+            fail("Exception not expected");
+        }
+
+        Assert.assertEquals(TestUtils.EXPIRES_IN, r.getExpiresIn());
+
+        initAndAssertError(r);
+    }
+
+    @Test
     public void testGetScope() throws Exception {
         OAuthJSONAccessTokenResponse r = null;
         try {
@@ -101,6 +116,10 @@ public class OAuthJSONAccessTokenRespons
 
         Assert.assertEquals(TestUtils.SCOPE, r.getScope());
 
+        initAndAssertError(r);
+    }
+
+    private void initAndAssertError(OAuthJSONAccessTokenResponse r) {
         try {
             new OAuthJSONAccessTokenResponse();
             r.init(TestUtils.ERROR_JSON_BODY,
@@ -108,7 +127,6 @@ public class OAuthJSONAccessTokenRespons
             fail("Exception expected");
         } catch (OAuthProblemException e) {
             Assert.assertNotNull(e.getError());
-
         }
     }
 
@@ -125,14 +143,7 @@ public class OAuthJSONAccessTokenRespons
 
         Assert.assertEquals(TestUtils.REFRESH_TOKEN, r.getRefreshToken());
 
-        try {
-            new OAuthJSONAccessTokenResponse();
-            r.init(TestUtils.ERROR_JSON_BODY,
-                OAuth.ContentType.JSON, 200);
-            fail("Exception expected");
-        } catch (OAuthProblemException e) {
-            Assert.assertNotNull(e.getError());
-        }
+        initAndAssertError(r);
     }
 
     @Test

Modified: oltu/trunk/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/utils/TestUtils.java
URL: http://svn.apache.org/viewvc/oltu/trunk/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/utils/TestUtils.java?rev=1732995&r1=1732994&r2=1732995&view=diff
==============================================================================
--- oltu/trunk/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/utils/TestUtils.java
(original)
+++ oltu/trunk/oauth-2.0/client/src/test/java/org/apache/oltu/oauth2/client/utils/TestUtils.java
Tue Mar  1 05:37:36 2016
@@ -39,10 +39,11 @@ public final class TestUtils {
 
     public static final String VALID_JSON_RESPONSE
         = "{\"expires_in\":3600,\"access_token\":\"b52d434791fd52316232b6cf2d3\",\"scope\":\"read\","
-        + "\"refresh_token\":\"test_refresh_token\"}";
+        + "\"token_type\":\"bearer\",\"refresh_token\":\"test_refresh_token\"}";
 
     public static final Long EXPIRES_IN = 3600l;
     public static final String ACCESS_TOKEN = "b52d434791fd52316232b6cf2d3";
+    public static final String TOKEN_TYPE = "bearer";
     public static final String SCOPE = "read";
     public static final String REFRESH_TOKEN = "test_refresh_token";
 
@@ -50,11 +51,6 @@ public final class TestUtils {
         = "{\"error_uri\":\"null\",\"error\":\"invalid_request\",\"state\":\"null\",\"error_description\":"
         + "\"Invalid grant_type parameter value\"}";
 
-    public static final String INVALID_JSON
-        = "\"expires_in\":3600,\"access_token\":\"b52d434791fd52316232b6cf2d3\"}";
-
-//    public static final String
-
     public static void expectNoErrorParameters(HttpServletRequest request) {
         expect(request.getParameter(OAuthError.OAUTH_ERROR))
             .andStubReturn(null);

Modified: oltu/trunk/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/token/BasicOAuthToken.java
URL: http://svn.apache.org/viewvc/oltu/trunk/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/token/BasicOAuthToken.java?rev=1732995&r1=1732994&r2=1732995&view=diff
==============================================================================
--- oltu/trunk/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/token/BasicOAuthToken.java
(original)
+++ oltu/trunk/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/token/BasicOAuthToken.java
Tue Mar  1 05:37:36 2016
@@ -25,6 +25,7 @@ package org.apache.oltu.oauth2.common.to
  */
 public class BasicOAuthToken implements OAuthToken {
     protected String accessToken;
+    protected String tokenType;
     protected Long expiresIn;
     protected String refreshToken;
     protected String scope;
@@ -32,29 +33,35 @@ public class BasicOAuthToken implements
     public BasicOAuthToken() {
     }
 
-    public BasicOAuthToken(String accessToken, Long expiresIn, String refreshToken, String
scope) {
+    public BasicOAuthToken(String accessToken, String tokenType, Long expiresIn, String refreshToken,
String scope) {
         this.accessToken = accessToken;
+        this.tokenType = tokenType;
         this.expiresIn = expiresIn;
         this.refreshToken = refreshToken;
         this.scope = scope;
     }
 
-    public BasicOAuthToken(String accessToken) {
-        this(accessToken, null, null, null);
+    public BasicOAuthToken(String accessToken, String tokenType) {
+        this(accessToken, tokenType, null, null, null);
     }
 
-    public BasicOAuthToken(String accessToken, Long expiresIn) {
-        this(accessToken, expiresIn, null, null);
+    public BasicOAuthToken(String accessToken, String tokenType, Long expiresIn) {
+        this(accessToken, tokenType, expiresIn, null, null);
     }
 
-    public BasicOAuthToken(String accessToken, Long expiresIn, String scope) {
-        this(accessToken, expiresIn, null, scope);
+    public BasicOAuthToken(String accessToken, String tokenType, Long expiresIn, String scope)
{
+        this(accessToken, tokenType, expiresIn, null, scope);
     }
 
     public String getAccessToken() {
         return accessToken;
     }
 
+    @Override
+    public String getTokenType() {
+        return tokenType;
+    }
+
     public Long getExpiresIn() {
         return expiresIn;
     }

Modified: oltu/trunk/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/token/OAuthToken.java
URL: http://svn.apache.org/viewvc/oltu/trunk/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/token/OAuthToken.java?rev=1732995&r1=1732994&r2=1732995&view=diff
==============================================================================
--- oltu/trunk/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/token/OAuthToken.java
(original)
+++ oltu/trunk/oauth-2.0/common/src/main/java/org/apache/oltu/oauth2/common/token/OAuthToken.java
Tue Mar  1 05:37:36 2016
@@ -21,12 +21,18 @@
 package org.apache.oltu.oauth2.common.token;
 
 /**
- *
+ * Interface declaring accessor methods for the basic fields of 
+ * an access token response. 
+ * <p> 
+ * See:
+ * <a href="http://tools.ietf.org/html/rfc6749#section-5.1">http://tools.ietf.org/html/rfc6749#section-5.1</a>
  */
 public interface OAuthToken {
 
     public String getAccessToken();
 
+    public String getTokenType();
+    
     public Long getExpiresIn();
 
     public String getRefreshToken();

Modified: oltu/trunk/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints/AuthzEndpoint.java
URL: http://svn.apache.org/viewvc/oltu/trunk/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints/AuthzEndpoint.java?rev=1732995&r1=1732994&r2=1732995&view=diff
==============================================================================
--- oltu/trunk/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints/AuthzEndpoint.java
(original)
+++ oltu/trunk/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints/AuthzEndpoint.java
Tue Mar  1 05:37:36 2016
@@ -73,6 +73,7 @@ public class AuthzEndpoint {
             }
             if (responseType.equals(ResponseType.TOKEN.toString())) {
                 builder.setAccessToken(oauthIssuerImpl.accessToken());
+                builder.setTokenType(OAuth.DEFAULT_TOKEN_TYPE.toString());
                 builder.setExpiresIn(3600l);
             }
 

Modified: oltu/trunk/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints/TokenEndpoint.java
URL: http://svn.apache.org/viewvc/oltu/trunk/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints/TokenEndpoint.java?rev=1732995&r1=1732994&r2=1732995&view=diff
==============================================================================
--- oltu/trunk/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints/TokenEndpoint.java
(original)
+++ oltu/trunk/oauth-2.0/integration-tests/src/test/java/org/apache/oltu/oauth2/integration/endpoints/TokenEndpoint.java
Tue Mar  1 05:37:36 2016
@@ -120,6 +120,7 @@ public class TokenEndpoint {
             OAuthResponse response = OAuthASResponse
                 .tokenResponse(HttpServletResponse.SC_OK)
                 .setAccessToken(oauthIssuerImpl.accessToken())
+                .setTokenType(OAuth.DEFAULT_TOKEN_TYPE.toString())
                 .setExpiresIn("3600")
                 .buildJSONMessage();
             return Response.status(response.getResponseStatus()).entity(response.getBody()).build();
@@ -131,4 +132,4 @@ public class TokenEndpoint {
         }
     }
 
-}
\ No newline at end of file
+}



Mime
View raw message