Skip to content

Commit

Permalink
Merge pull request #1237 from romeara/bugfix/romeara/oauth-client-bea…
Browse files Browse the repository at this point in the history
…rer-case-insensitive

Match token type case insensitively to broaden supported platforms
  • Loading branch information
thboileau committed Oct 1, 2016
2 parents 2034858 + 6e41226 commit 618525d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
Expand Up @@ -128,7 +128,7 @@ public Response handleOutbound(Request request) {
throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED,
"Token not found");
}
if (token.getTokenType().equals(TOKEN_TYPE_BEARER)) {
if (TOKEN_TYPE_BEARER.equalsIgnoreCase(token.getTokenType())) {
if (isUseBodyMethod()) {
Representation entity = request.getEntity();
if (entity != null
Expand Down
Expand Up @@ -91,6 +91,42 @@ public boolean isExpired() {
return false;
}
};

public static Token SPRING_STUB_TOKEN = new ServerToken() {

public String getAccessToken() {
return STUB_ACCESS_TOKEN;
}

public String getTokenType() {
//Spring returns bearer in lower case
return "bearer";
}

public int getExpirePeriod() {
return 3600;
}

public String getRefreshToken() {
return STUB_REFRESH_TOKEN;
}

public String[] getScope() {
return new String[] { "a", "b" };
}

public String getUsername() {
return STUB_USERNAME;
}

public String getClientId() {
return STUB_CLIENT_ID;
}

public boolean isExpired() {
return false;
}
};

public static final Client STUB_CLIENT = new Client() {

Expand Down
Expand Up @@ -152,4 +152,14 @@ public void testCase3() {
resource.addQueryParameter("foo", "bar");
resource.get();
}

//Test compatibility with modules that don't match token type case
@Test
public void testCase4() {
ProtectedClientResource resource = new ProtectedClientResource(
new Reference(baseURI, "/app/resource1"));
resource.setToken(SPRING_STUB_TOKEN);
resource.setUseBodyMethod(false);
resource.get();
}
}

0 comments on commit 618525d

Please sign in to comment.