Skip to content

Commit

Permalink
Auth.authorize(): use supplied token or tokenDetails
Browse files Browse the repository at this point in the history
As in proposed RSA10e spec clarification in PR
ably/docs#186
  • Loading branch information
Tim Renouf authored and psolstice committed Dec 23, 2016
1 parent 3036e80 commit e2e23e8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/src/main/java/io/ably/lib/http/Http.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ private String getAuthorizationHeader(boolean renew) throws AblyException {
authHeader = "Basic " + Base64Coder.encodeString(auth.getBasicCredentials());
} else {
if (renew)
auth.authorize(null, null);
auth.renew();
else
auth.ensureValidAuth();
authHeader = "Bearer " + auth.getTokenAuth().getEncodedToken();
Expand Down
24 changes: 22 additions & 2 deletions lib/src/main/java/io/ably/lib/rest/Auth.java
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,17 @@ public TokenDetails authorize(TokenParams params, AuthOptions options) throws Ab
options = (options == null) ? this.authOptions : options.copy();
params = (params == null) ? this.tokenParams : params.copy();

TokenDetails tokenDetails = tokenAuth.authorize(params, options, /*force=*/true);

/* RSA10e (as clarified in PR https://github.com/ably/docs/pull/186 )
* Use supplied token or tokenDetails if any. */
if (authOptions.token != null)
authOptions.tokenDetails = new TokenDetails(authOptions.token);
TokenDetails tokenDetails;
if (authOptions.tokenDetails != null) {
tokenDetails = authOptions.tokenDetails;
tokenAuth.setTokenDetails(tokenDetails);
} else {
tokenDetails = tokenAuth.authorize(params, options, /*force=*/true);
}
ably.onAuthUpdated();
return tokenDetails;
}
Expand All @@ -410,6 +419,17 @@ public TokenDetails ensureValidAuth() throws AblyException {
return tokenAuth.authorize(this.tokenParams, this.authOptions, /*force=*/false);
}

/**
* Renew auth credentials.
* Will obtain a new token, even if we already have an apparently valid one.
* Authorization will use the parameters supplied on construction.
*/
public TokenDetails renew() throws AblyException {
TokenDetails tokenDetails = tokenAuth.authorize(this.tokenParams, this.authOptions, /*force=*/true);
ably.onAuthUpdated();
return tokenDetails;
}

/**
* Make a token request. This will make a token request now, even if the library already
* has a valid token. It would typically be used to issue tokens for use by other clients.
Expand Down

0 comments on commit e2e23e8

Please sign in to comment.