From ed4555286aad9519673eacb8d75e4737564c5313 Mon Sep 17 00:00:00 2001
From: majimene
* private AuthorizationFlow flow; - * + * * public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { * String url = flow.newExplicitAuthorizationUrl().setState("xyz") * .setRedirectUri("https://client.example.com/rd").build(); @@ -270,10 +276,10 @@ public AuthorizationCodeRequestUrl newExplicitAuthorizationUrl() { * {@link #getAuthorizationServerEncodedUrl()}, {@link #getClientId()}, and * {@link #getScopes()}. Sample usage: * - * + * ** private AuthorizationFlow flow; - * + * * public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { * String url = flow.newImplicitAuthorizationUrl().setState("xyz") * .setRedirectUri("https://client.example.com/rd").build(); @@ -282,14 +288,19 @@ public AuthorizationCodeRequestUrl newExplicitAuthorizationUrl() { **/ public BrowserClientRequestUrl newImplicitAuthorizationUrl() { - return new BrowserClientRequestUrl(getAuthorizationServerEncodedUrl(), getClientId()) + BrowserClientRequestUrl browserClientRequestUrl = new BrowserClientRequestUrl(getAuthorizationServerEncodedUrl(), getClientId()) .setScopes(getScopes()); + CollectionresponseTypes = getResponseTypes(); + if (responseTypes != null && !responseTypes.isEmpty()) { + browserClientRequestUrl.setResponseTypes(getResponseTypes()); + } + return browserClientRequestUrl; } /** * Creates a new credential for the given user ID based on the given token * response and store in the credential store. - * + * * @param response OAuth 1.0a authorization token response * @param userId user ID or {@code null} if not using a persisted credential * store @@ -297,7 +308,7 @@ public BrowserClientRequestUrl newImplicitAuthorizationUrl() { * @throws IOException */ public OAuthHmacCredential createAndStoreCredential(OAuthCredentialsResponse response, - String userId) throws IOException { + String userId) throws IOException { OAuthHmacCredential credential = new10aCredential(userId) .setAccessToken(response.token) .setTokenSharedSecret(response.tokenSecret); @@ -314,7 +325,7 @@ public OAuthHmacCredential createAndStoreCredential(OAuthCredentialsResponse res /** * Creates a new credential for the given user ID based on the given token * response and store in the credential store. - * + * * @param response implicit authorization token response * @param userId user ID or {@code null} if not using a persisted credential * store @@ -338,7 +349,7 @@ public Credential createAndStoreCredential(ImplicitResponseUrl implicitResponse, /** * Returns a new OAuth 1.0a credential instance based on the given user ID. - * + * * @param userId user ID or {@code null} if not using a persisted credential * store */ @@ -365,7 +376,7 @@ private OAuthHmacCredential new10aCredential(String userId) { /** * Returns a new OAuth 2.0 credential instance based on the given user ID. - * + * * @param userId user ID or {@code null} if not using a persisted credential * store */ @@ -387,6 +398,14 @@ private Credential newCredential(String userId) { return builder.build(); } + + /** + * Returns the a collection of response types. + */ + public final Collection getResponseTypes() { + return this.responseTypes; + } + /** * Authorization flow builder. * @@ -402,6 +421,9 @@ public static class Builder extends /** Temporary token request URL */ String temporaryTokenRequestUrl; + /** Collection of response types. */ + Collection
responseTypes = Lists.newArrayList(); + /** * @param method method of presenting the access token to the resource * server (for example @@ -417,12 +439,12 @@ public static class Builder extends * @param authorizationServerEncodedUrl authorization server encoded URL */ public Builder(AccessMethod method, - HttpTransport transport, - JsonFactory jsonFactory, - GenericUrl tokenServerUrl, - HttpExecuteInterceptor clientAuthentication, - String clientId, - String authorizationServerEncodedUrl) { + HttpTransport transport, + JsonFactory jsonFactory, + GenericUrl tokenServerUrl, + HttpExecuteInterceptor clientAuthentication, + String clientId, + String authorizationServerEncodedUrl) { super(method, transport, jsonFactory, @@ -442,7 +464,7 @@ public AuthorizationFlow build() { /** * Sets the temporary token request URL. - * + * * @param temporaryTokenRequestUrl * @return */ @@ -453,13 +475,22 @@ public Builder setTemporaryTokenRequestUrl(String temporaryTokenRequestUrl) { /** * Returns the temporary token request URL. - * + * * @return */ public String getTemporaryTokenRequestUrl() { return temporaryTokenRequestUrl; } + /** + * Returns the response types. + * + * @return + */ + public Collection getResponseTypes() { + return responseTypes; + } + @Override public Builder setMethod(AccessMethod method) { return (Builder) super.setMethod(method); @@ -530,6 +561,11 @@ public Builder setScopes(Collection scopes) { return (Builder) super.setScopes(scopes); } + public Builder setResponseTypes(Collection responseTypes) { + this.responseTypes = Preconditions.checkNotNull(responseTypes); + return this; + } + /** * Sets the credential created listener or {@code null} for none. * * diff --git a/samples/src/main/java/com/wuman/oauth/samples/OAuth.java b/samples/src/main/java/com/wuman/oauth/samples/OAuth.java index fb4f152..91600dd 100644 --- a/samples/src/main/java/com/wuman/oauth/samples/OAuth.java +++ b/samples/src/main/java/com/wuman/oauth/samples/OAuth.java @@ -41,7 +41,19 @@ public static OAuth newInstance(Context context, final String redirectUri, List
scopes) { return newInstance(context, fragmentManager, client, - authorizationRequestUrl, tokenServerUrl, redirectUri, scopes, null); + authorizationRequestUrl, tokenServerUrl, redirectUri, scopes, null, null); + } + + public static OAuth newInstance(Context context, + FragmentManager fragmentManager, + ClientParametersAuthentication client, + String authorizationRequestUrl, + String tokenServerUrl, + final String redirectUri, + List scopes, + String temporaryTokenRequestUrl) { + return newInstance(context, fragmentManager, client, + authorizationRequestUrl, tokenServerUrl, redirectUri, scopes, temporaryTokenRequestUrl, null); } public static OAuth newInstance(Context context, @@ -51,7 +63,8 @@ public static OAuth newInstance(Context context, String tokenServerUrl, final String redirectUri, List scopes, - String temporaryTokenRequestUrl) { + String temporaryTokenRequestUrl, + List responseTypes) { Preconditions.checkNotNull(client.getClientId()); boolean fullScreen = context.getSharedPreferences("Preference", 0) .getBoolean(SamplesActivity.KEY_AUTH_MODE, false); @@ -70,6 +83,10 @@ public static OAuth newInstance(Context context, authorizationRequestUrl) .setScopes(scopes) .setCredentialStore(credentialStore); + // set response types + if (responseTypes != null) { + flowBuilder.setResponseTypes(responseTypes); + } // set temporary token request url for 1.0a flow if applicable if (!TextUtils.isEmpty(temporaryTokenRequestUrl)) { flowBuilder.setTemporaryTokenRequestUrl(temporaryTokenRequestUrl);