Skip to content
Closed

1.5 #114

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
51de154
Change Maven groupId to com.google.oauth-client & some minor release …
Jul 26, 2011
3702715
Fixes to AccessProtectedResources and subclasses.
Jul 26, 2011
c91b1b3
Use a Maven version range for HTTP project dependency
Jul 27, 2011
639b317
Dependency on http extensions android2 and android3; predictable vers…
Jul 28, 2011
f1add95
maven-release-plugin: change tagNameFormat
Jul 29, 2011
bbcb351
Backed out changeset 2d079162d7e1
Jul 29, 2011
667bb59
[maven-release-plugin] prepare release 1.5.0-alpha
Jul 29, 2011
c6de972
[maven-release-plugin] copy for tag 1.5.0-alpha
Jul 29, 2011
1c42c95
[maven-release-plugin] prepare for next development iteration
Jul 29, 2011
1025392
[maven-release-plugin] prepare release 1.5.0-beta
Jul 29, 2011
fbe3d1d
[maven-release-plugin] copy for tag 1.5.0-beta
Jul 29, 2011
fa57cb9
[maven-release-plugin] prepare for next development iteration
Jul 29, 2011
db1d47d
start next bug fix release
Jul 29, 2011
e329f17
[Issue 13] Missing JavaDoc link
Sep 23, 2011
7f2ffcb
Allow refreshToken to be null in OAuth2Credential and AccessProtected…
rmistry Oct 17, 2011
fa7ffdd
[maven-release-plugin] prepare release 1.5.1-beta
rmistry Oct 17, 2011
ede4edb
[maven-release-plugin] copy for tag 1.5.1-beta
rmistry Oct 17, 2011
d0649e1
[maven-release-plugin] prepare for next development iteration
rmistry Oct 17, 2011
13a395d
start next bug fix version
rmistry Oct 17, 2011
ab54010
Point to google-http-java-client 1.5.3-beta
rmistry Oct 23, 2011
c3c1c81
[maven-release-plugin] prepare release 1.5.2-beta
rmistry Oct 23, 2011
4620d12
[maven-release-plugin] copy for tag 1.5.2-beta
rmistry Oct 23, 2011
5036ec1
[maven-release-plugin] prepare for next development iteration
rmistry Oct 23, 2011
c4d8edf
start next bug fix version
rmistry Oct 23, 2011
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Allow refreshToken to be null in OAuth2Credential and AccessProtected…
…Resource
  • Loading branch information
rmistry committed Oct 17, 2011
commit 7f2ffcbf807a7a759485c30b69115cac04c3cc26
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ public final class OAuth2Credential implements Credential, InstanceCallbacks {
* @param userId Key that can be used to associate this Credential object with an end user.
* @param accessToken Access token that can be used to authorize this request.
* @param refreshToken Token that can be given to the token server in exchange for a new access
* token.
* token or {@code null} for none.
*/
public OAuth2Credential(String userId, String accessToken, String refreshToken) {
this.userId = Preconditions.checkNotNull(userId);
this.accessToken = Preconditions.checkNotNull(accessToken);
this.refreshToken = Preconditions.checkNotNull(refreshToken);
this.refreshToken = refreshToken;
initializeAfterConstruction();
}

Expand All @@ -93,9 +93,7 @@ public OAuth2Credential(String userId, String accessToken, String refreshToken)
* @param accessToken Access token that can be used to authorize this request.
*/
public OAuth2Credential(String userId, String accessToken) {
this.userId = Preconditions.checkNotNull(userId);
this.accessToken = Preconditions.checkNotNull(accessToken);
initializeAfterConstruction();
this(userId, accessToken, null);
}

/**
Expand Down Expand Up @@ -146,14 +144,6 @@ public boolean handleResponse(
*/
public void initializeForRefresh(String clientId, String clientSecret, String refreshUrl,
JsonFactory jsonFactory, HttpTransport transport) {
Preconditions.checkArgument(
refreshToken != null, "Must construct the object with a refreshToken");
Preconditions.checkNotNull(clientId);
Preconditions.checkNotNull(clientSecret);
Preconditions.checkNotNull(clientSecret);
Preconditions.checkNotNull(transport);
Preconditions.checkNotNull(jsonFactory);

authInterceptor = new AccessProtectedResource(accessToken,
Method.AUTHORIZATION_HEADER,
transport,
Expand Down Expand Up @@ -184,9 +174,9 @@ public void setAccessToken(String accessToken) {
}

/**
* Return the refresh token with which this object was constructed. This can be used for out of
* band use cases, but most users should just let the credential be refreshed by the library when
* a call fails.
* Return the refresh token with which this object was constructed or {@code null} for none. This
* can be used for out of band use cases, but most users should just let the credential be
* refreshed by the library when a call fails.
*/
public String getRefreshToken() {
return refreshToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ public enum Method {
private final String refreshToken;

/**
* Constructor that uses a non-expired access token.
*
* @param accessToken access token or {@code null} for none (does not call
* {@link #setAccessToken(String)})
* @param method method of accessing protected resources
Expand All @@ -168,7 +170,8 @@ public AccessProtectedResource(String accessToken, Method method) {
* @param authorizationServerUrl encoded authorization server URL
* @param clientId client identifier
* @param clientSecret client secret
* @param refreshToken refresh token associated with the access token to be refreshed
* @param refreshToken refresh token associated with the access token to be refreshed or
* {@code null} for none
*/
public AccessProtectedResource(String accessToken,
Method method,
Expand All @@ -185,7 +188,7 @@ public AccessProtectedResource(String accessToken,
this.authorizationServerUrl = Preconditions.checkNotNull(authorizationServerUrl);
this.clientId = Preconditions.checkNotNull(clientId);
this.clientSecret = Preconditions.checkNotNull(clientSecret);
this.refreshToken = Preconditions.checkNotNull(refreshToken);
this.refreshToken = refreshToken;
}

/** Returns the access token or {@code null} for none. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,20 @@ public void testRefreshToken_noRefreshToken() throws IOException {
assertFalse(accesss.refreshToken());
}

public void testRefreshToken_noRefreshToken2() throws IOException {
AccessTokenTransport transport = new AccessTokenTransport();
AccessProtectedResource access = new AccessProtectedResource(ACCESS_TOKEN,
Method.QUERY_PARAMETER,
transport,
JSON_FACTORY,
AUTHORIZATION_SERVER_URL,
CLIENT_ID,
CLIENT_SECRET,
null);
assertFalse(access.refreshToken());
assertEquals(ACCESS_TOKEN, access.getAccessToken());
}

public void testRefreshToken_refreshToken() throws IOException {
AccessTokenTransport transport = new AccessTokenTransport();
AccessProtectedResource access = new AccessProtectedResource(ACCESS_TOKEN,
Expand Down