mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-08 16:36:13 +00:00
Include refresh token operation in library, builder
This commit is contained in:
parent
aa717b3e7b
commit
99334c2e45
@ -44,26 +44,34 @@ public class OAuth2GetRefreshedAccessTokenOperation extends RemoteOperation {
|
|||||||
|
|
||||||
private static final String TAG = OAuth2GetRefreshedAccessTokenOperation.class.getSimpleName();
|
private static final String TAG = OAuth2GetRefreshedAccessTokenOperation.class.getSimpleName();
|
||||||
|
|
||||||
|
private String mGrantType;
|
||||||
private String mClientId;
|
private String mClientId;
|
||||||
private String mClientSecret;
|
private String mClientSecret;
|
||||||
private String mGrantType;
|
|
||||||
|
|
||||||
private String mRefreshToken;
|
private String mRefreshToken;
|
||||||
|
|
||||||
private Map<String, String> mResultTokenMap;
|
private Map<String, String> mResultTokenMap;
|
||||||
|
|
||||||
|
private final String mAccessTokenEndpointPath;
|
||||||
|
|
||||||
|
|
||||||
public OAuth2GetRefreshedAccessTokenOperation(
|
public OAuth2GetRefreshedAccessTokenOperation(
|
||||||
|
String grantType,
|
||||||
String clientId,
|
String clientId,
|
||||||
String secretId,
|
String secretId,
|
||||||
String grantType,
|
String refreshToken,
|
||||||
String refreshToken
|
String accessTokenEndpointPath
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
mGrantType = grantType;
|
||||||
mClientId = clientId;
|
mClientId = clientId;
|
||||||
mClientSecret = secretId;
|
mClientSecret = secretId;
|
||||||
mGrantType = grantType;
|
|
||||||
mRefreshToken = refreshToken;
|
mRefreshToken = refreshToken;
|
||||||
mResultTokenMap = null;
|
mResultTokenMap = null;
|
||||||
|
|
||||||
|
mAccessTokenEndpointPath =
|
||||||
|
accessTokenEndpointPath != null ?
|
||||||
|
accessTokenEndpointPath :
|
||||||
|
OwnCloudOAuth2Provider.ACCESS_TOKEN_ENDPOINT_PATH
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -79,6 +87,7 @@ public class OAuth2GetRefreshedAccessTokenOperation extends RemoteOperation {
|
|||||||
nameValuePairs[2] = new NameValuePair(OAuth2Constants.KEY_REFRESH_TOKEN, mRefreshToken);
|
nameValuePairs[2] = new NameValuePair(OAuth2Constants.KEY_REFRESH_TOKEN, mRefreshToken);
|
||||||
|
|
||||||
Uri.Builder uriBuilder = client.getBaseUri().buildUpon();
|
Uri.Builder uriBuilder = client.getBaseUri().buildUpon();
|
||||||
|
uriBuilder.appendEncodedPath(mAccessTokenEndpointPath);
|
||||||
|
|
||||||
postMethod = new PostMethod(uriBuilder.build().toString());
|
postMethod = new PostMethod(uriBuilder.build().toString());
|
||||||
postMethod.setRequestBody(nameValuePairs);
|
postMethod.setRequestBody(nameValuePairs);
|
||||||
|
@ -31,7 +31,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperation;
|
|||||||
public interface OAuth2RequestBuilder {
|
public interface OAuth2RequestBuilder {
|
||||||
|
|
||||||
enum OAuthRequest {
|
enum OAuthRequest {
|
||||||
GET_AUTHORIZATION_CODE, CREATE_ACCESS_TOKEN
|
GET_AUTHORIZATION_CODE, CREATE_ACCESS_TOKEN, REFRESH_ACCESS_TOKEN
|
||||||
}
|
}
|
||||||
|
|
||||||
void setRequest(OAuthRequest operation);
|
void setRequest(OAuthRequest operation);
|
||||||
@ -40,8 +40,9 @@ public interface OAuth2RequestBuilder {
|
|||||||
|
|
||||||
void setAuthorizationCode(String code);
|
void setAuthorizationCode(String code);
|
||||||
|
|
||||||
|
void setRefreshToken(String refreshToken);
|
||||||
|
|
||||||
RemoteOperation buildOperation();
|
RemoteOperation buildOperation();
|
||||||
|
|
||||||
String buildUri();
|
String buildUri();
|
||||||
|
}
|
||||||
}
|
|
@ -37,6 +37,7 @@ public class OwnCloudOAuth2RequestBuilder implements OAuth2RequestBuilder {
|
|||||||
private OAuthRequest mRequest;
|
private OAuthRequest mRequest;
|
||||||
private OAuth2GrantType mGrantType = OAuth2GrantType.AUTHORIZATION_CODE;
|
private OAuth2GrantType mGrantType = OAuth2GrantType.AUTHORIZATION_CODE;
|
||||||
private String mCode;
|
private String mCode;
|
||||||
|
private String mRefreshToken;
|
||||||
|
|
||||||
public OwnCloudOAuth2RequestBuilder(OwnCloudOAuth2Provider ownCloudOAuth2Provider) {
|
public OwnCloudOAuth2RequestBuilder(OwnCloudOAuth2Provider ownCloudOAuth2Provider) {
|
||||||
mOAuth2Provider = ownCloudOAuth2Provider;
|
mOAuth2Provider = ownCloudOAuth2Provider;
|
||||||
@ -57,6 +58,11 @@ public class OwnCloudOAuth2RequestBuilder implements OAuth2RequestBuilder {
|
|||||||
mCode = code;
|
mCode = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setRefreshToken(String refreshToken) {
|
||||||
|
mRefreshToken = refreshToken;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RemoteOperation buildOperation() {
|
public RemoteOperation buildOperation() {
|
||||||
if (OAuth2GrantType.AUTHORIZATION_CODE != mGrantType) {
|
if (OAuth2GrantType.AUTHORIZATION_CODE != mGrantType) {
|
||||||
@ -65,9 +71,10 @@ public class OwnCloudOAuth2RequestBuilder implements OAuth2RequestBuilder {
|
|||||||
OAuth2GrantType.AUTHORIZATION_CODE.getValue() + " is supported"
|
OAuth2GrantType.AUTHORIZATION_CODE.getValue() + " is supported"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
OAuth2ClientConfiguration clientConfiguration = mOAuth2Provider.getClientConfiguration();
|
||||||
|
|
||||||
switch(mRequest) {
|
switch(mRequest) {
|
||||||
case CREATE_ACCESS_TOKEN:
|
case CREATE_ACCESS_TOKEN:
|
||||||
OAuth2ClientConfiguration clientConfiguration = mOAuth2Provider.getClientConfiguration();
|
|
||||||
return new OAuth2GetAccessTokenOperation(
|
return new OAuth2GetAccessTokenOperation(
|
||||||
mGrantType.getValue(),
|
mGrantType.getValue(),
|
||||||
mCode,
|
mCode,
|
||||||
@ -76,6 +83,15 @@ public class OwnCloudOAuth2RequestBuilder implements OAuth2RequestBuilder {
|
|||||||
clientConfiguration.getRedirectUri(),
|
clientConfiguration.getRedirectUri(),
|
||||||
mOAuth2Provider.getAccessTokenEndpointPath()
|
mOAuth2Provider.getAccessTokenEndpointPath()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
case REFRESH_ACCESS_TOKEN:
|
||||||
|
return new OAuth2GetRefreshedAccessTokenOperation(
|
||||||
|
mGrantType.getValue(),
|
||||||
|
clientConfiguration.getClientId(),
|
||||||
|
clientConfiguration.getClientSecret(),
|
||||||
|
mRefreshToken,
|
||||||
|
mOAuth2Provider.getAccessTokenEndpointPath()
|
||||||
|
);
|
||||||
default:
|
default:
|
||||||
throw new UnsupportedOperationException(
|
throw new UnsupportedOperationException(
|
||||||
"Unsupported request"
|
"Unsupported request"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user