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