本文整理汇总了Java中com.google.api.client.auth.oauth2.AuthorizationCodeRequestUrl类的典型用法代码示例。如果您正苦于以下问题:Java AuthorizationCodeRequestUrl类的具体用法?Java AuthorizationCodeRequestUrl怎么用?Java AuthorizationCodeRequestUrl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AuthorizationCodeRequestUrl类属于com.google.api.client.auth.oauth2包,在下文中一共展示了AuthorizationCodeRequestUrl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: authorize
import com.google.api.client.auth.oauth2.AuthorizationCodeRequestUrl; //导入依赖的package包/类
/**
* Authorizes the installed application to access user's protected data.
*/
public static void authorize(String userID, boolean driveAPI) throws IOException {
// load client secrets
// set up authorization code flow
Collection<String> scopes = new ArrayList<String>();
scopes.add(GamesScopes.GAMES);
if (driveAPI)
scopes.add(DriveScopes.DRIVE_APPDATA);
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY,
clientSecrets, scopes).setDataStoreFactory(dataStoreFactory).build();
// authorize
Credential credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()) {
// Override open browser not working well on Linux and maybe other
// OS.
protected void onAuthorization(AuthorizationCodeRequestUrl authorizationUrl) throws java.io.IOException {
Gdx.net.openURI(authorizationUrl.build());
}
}.authorize(userID);
games = new Games.Builder(httpTransport, JSON_FACTORY, credential).setApplicationName(applicationName).build();
if (driveAPI)
drive = new Drive.Builder(httpTransport, JSON_FACTORY, credential).setApplicationName(applicationName).build();
}
示例2: authorizationRequestUri
import com.google.api.client.auth.oauth2.AuthorizationCodeRequestUrl; //导入依赖的package包/类
/**
* Generates the authorization request URI for the client credentials.
* @param redirectionEndpoint redirection endpoint for the authorization
* and token requests; if this value is <code>null</code>, the
* <code>redirect_uri</code> parameter shall not be included.
* @param state opaque state string for the authorization request; if this
* argument is <code>null</code>, the <code>state</code> parameter shall
* not be used
* @return authorization request URI
* @throws NullPointerException if this object had no client credentials
* @since 5.0
*/
public String authorizationRequestUri(
URI redirectionEndpoint, String state) {
redirectionEndpointUri = null;
if (redirectionEndpoint != null) {
redirectionEndpointUri = redirectionEndpoint.toString();
}
AuthorizationCodeFlow flow = getAuthorizationCodeFlow(false);
AuthorizationCodeRequestUrl request = flow.newAuthorizationUrl();
if (redirectionEndpointUri != null) {
request.setRedirectUri(redirectionEndpointUri);
}
if (state != null) {
request.setState(state);
}
return request.build();
}
示例3: authorize
import com.google.api.client.auth.oauth2.AuthorizationCodeRequestUrl; //导入依赖的package包/类
private String authorize(String redirectUri) {
AuthorizationCodeRequestUrl authorizationUrl;
Details web = new Details();
GoogleCalendarSettings googleCalendarSettings =
settingsService.getSettings().getCalendarSettings().getGoogleCalendarSettings();
web.setClientId(googleCalendarSettings.getClientId());
web.setClientSecret(googleCalendarSettings.getClientSecret());
GoogleClientSecrets clientSecrets = new GoogleClientSecrets();
clientSecrets.setWeb(web);
flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY, clientSecrets,
Collections.singleton(CalendarScopes.CALENDAR))
.setApprovalPrompt("force")
.setAccessType("offline")
.build();
authorizationUrl = flow.newAuthorizationUrl().setRedirectUri(redirectUri);
LOG.info("using authorizationUrl " + authorizationUrl);
return authorizationUrl.build();
}
示例4: onAuthorization
import com.google.api.client.auth.oauth2.AuthorizationCodeRequestUrl; //导入依赖的package包/类
protected void onAuthorization( AuthorizationCodeRequestUrl authorizationUrl ) throws IOException {
String url = authorizationUrl.build();
Spoon spoon = Spoon.getInstance();
if ( spoon != null ) {
Display.getDefault().syncExec( new Runnable() {
public void run() {
Shell shell = spoon.getShell();
GoogleAuthorizationDialog authorizationDialog = new GoogleAuthorizationDialog( shell, getReceiver() );
authorizationDialog.open( url );
}
} );
} else {
browse( url );
}
}
示例5: onAuthorization
import com.google.api.client.auth.oauth2.AuthorizationCodeRequestUrl; //导入依赖的package包/类
@Override
protected void onAuthorization(
AuthorizationCodeRequestUrl authorizationUrl)
throws IOException {
String authorizationUrlAsString = authorizationUrl.build();
Display display = Display.getDefault();
display.syncExec(() -> copyTextToClipboard(display, authorizationUrlAsString));
monitor.subTask("Please authorize the application in your browser. Url has been copied to clipboard");
openInExternalBrowser(URI.create(authorizationUrlAsString));
}
示例6: onAuthorization
import com.google.api.client.auth.oauth2.AuthorizationCodeRequestUrl; //导入依赖的package包/类
@Override
protected void onAuthorization(AuthorizationCodeRequestUrl authorizationUrl) throws IOException {
monitor.subTask("Please open the following address in your browser:" + authorizationUrl);
// use an old browser so that we see the old sign-in page
try (final WebClient webClient = new WebClient(INTERNET_EXPLORER_6)) {
webClient.getOptions().setJavaScriptEnabled(true);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
webClient.getOptions().setThrowExceptionOnScriptError(false);
HtmlPage nextPage = signIn(webClient, authorizationUrl.build());
if (isSelectChallengePage(nextPage)) {
nextPage = selectEmailRecoveryAsSignInChallenge(webClient, nextPage);
System.out.println("Selected recovery email confirmation as challenge");
nextPage = confirmRecoveryEmail(webClient, nextPage);
System.out.println("Used recovery email to confirm it's us");
allowAccess(webClient, nextPage);
} else if (isConfirmRecoveryEmailPage(nextPage)) {
nextPage = confirmRecoveryEmail(webClient, nextPage);
System.out.println("Used recovery email to confirm it's us");
allowAccess(webClient, nextPage);
} else {
allowAccess(webClient, nextPage);
}
}
if (authorizationListener != null) {
authorizationListener.onAuthorization();
}
}
示例7: codeFlowAuthenticationUrl
import com.google.api.client.auth.oauth2.AuthorizationCodeRequestUrl; //导入依赖的package包/类
/**
* Generates an Authentication Request URL to the Authorization Endpoint to start an Code Flow.
* When using the Code Flow, all tokens are returned from the Token Endpoint.
* The Authorization Server can authenticate the Client before exchanging the Authorization Code
* for an Access Token.
* @see <a href="http://openid.net/specs/openid-connect-core-1_0.html#CodeFlowAuth">Code Flow</a>
*
* @param state the state used to maintain state between the request and the callback.
* @return the Authentication Request URL
*/
private AuthorizationRequestUrl codeFlowAuthenticationUrl(String state) {
List<String> scopesList = Arrays.asList(scopes);
//noinspection UnnecessaryLocalVariable
AuthorizationCodeRequestUrl request = new AuthorizationCodeRequestUrl(authorizationEndpoint, clientId)
.setRedirectUri(redirectUrl)
.setScopes(scopesList)
.setState(state)
.set("nonce", ""); //TODO: nonce is optional, needs to include per-session state and be unguessable to attackers. We should try to generate one.
return request;
}
示例8: getAuthenticateUrl
import com.google.api.client.auth.oauth2.AuthorizationCodeRequestUrl; //导入依赖的package包/类
/**
* Create authentication URL.
*
* @param requestUrl URL of current HTTP request. This parameter required to be able determine URL
* for redirection after authentication. If URL contains query parameters they will be copy to
* 'state' parameter and returned to callback method.
* @param scopes specify exactly what type of access needed
* @return URL for authentication
*/
public String getAuthenticateUrl(URL requestUrl, List<String> scopes)
throws OAuthAuthenticationException {
if (!isConfigured()) {
throw new OAuthAuthenticationException("Authenticator is not configured");
}
AuthorizationCodeRequestUrl url =
flow.newAuthorizationUrl().setRedirectUri(findRedirectUrl(requestUrl)).setScopes(scopes);
url.setState(prepareState(requestUrl));
return url.build();
}
示例9: onAuthorization
import com.google.api.client.auth.oauth2.AuthorizationCodeRequestUrl; //导入依赖的package包/类
@Override
protected void onAuthorization(AuthorizationCodeRequestUrl authorizationUrl)
throws IOException {
final String url = authorizationUrl.build() ;
Platform.runLater(new Runnable() {
@Override
public void run() {
logger.info("Authorization url: " + url);
browser.show();
browser.goTo(url) ;
}
});
}
示例10: onAuthorization
import com.google.api.client.auth.oauth2.AuthorizationCodeRequestUrl; //导入依赖的package包/类
@Override
protected void onAuthorization(HttpServletRequest req,
HttpServletResponse resp,
AuthorizationCodeRequestUrl authorizationUrl)
throws ServletException, IOException {
authorizationUrl.setState(req.getParameter("state"));
super.onAuthorization(req, resp, authorizationUrl);
}
示例11: authorizeExplicitly
import com.google.api.client.auth.oauth2.AuthorizationCodeRequestUrl; //导入依赖的package包/类
/**
* Authorizes the Android application to access user's protected data using
* the Explicit Authorization Code flow in OAuth 2.0.
*
* @param userId user ID or {@code null} if not using a persisted credential
* store
* @param callback Callback to invoke when the request completes,
* {@code null} for no callback
* @param handler {@link Handler} identifying the callback thread,
* {@code null} for the main thread
* @return An {@link OAuthFuture} which resolves to a {@link Credential}
*/
public OAuthFuture<Credential> authorizeExplicitly(final String userId,
final OAuthCallback<Credential> callback, Handler handler) {
Preconditions.checkNotNull(userId);
final Future2Task<Credential> task = new Future2Task<Credential>(handler, callback) {
@Override
public void doWork() throws Exception {
try {
Credential credential = mFlow.loadCredential(userId);
LOGGER.info("authorizeExplicitly");
if (credential != null && credential.getAccessToken() != null
&& (credential.getRefreshToken() != null ||
credential.getExpiresInSeconds() == null ||
credential.getExpiresInSeconds() > 60)) {
set(credential);
return;
}
String redirectUri = mUIController.getRedirectUri();
AuthorizationCodeRequestUrl authorizationUrl = mFlow
.newExplicitAuthorizationUrl()
.setRedirectUri(redirectUri);
mUIController.requestAuthorization(authorizationUrl);
String code = mUIController.waitForExplicitCode();
TokenResponse response = mFlow.newTokenRequest(code)
.setRedirectUri(redirectUri).execute();
credential = mFlow.createAndStoreCredential(response, userId);
set(credential);
} finally {
mUIController.stop();
}
}
};
// run the task in a background thread
submitTaskToExecutor(task);
return task;
}
示例12: requestAuthorization
import com.google.api.client.auth.oauth2.AuthorizationCodeRequestUrl; //导入依赖的package包/类
@Override
public void requestAuthorization(AuthorizationCodeRequestUrl authorizationRequestUrl) {
internalRequestAuthorization(authorizationRequestUrl);
}
示例13: newInstance
import com.google.api.client.auth.oauth2.AuthorizationCodeRequestUrl; //导入依赖的package包/类
@TargetApi(HONEYCOMB)
public static final OAuthDialogFragment newInstance(
GenericUrl authorizationRequestUrl,
DialogFragmentController controller) {
Bundle args = new Bundle();
args.putString(ARG_AUTHORIZATION_REQUEST_URL, authorizationRequestUrl.build());
if (authorizationRequestUrl instanceof OAuthAuthorizeTemporaryTokenUrl) {
args.putString(ARG_AUTHORIZATION_TYPE, AUTHORIZATION_10A);
} else if (authorizationRequestUrl instanceof AuthorizationCodeRequestUrl) {
args.putString(ARG_AUTHORIZATION_TYPE, AUTHORIZATION_EXPLICIT);
} else {
args.putString(ARG_AUTHORIZATION_TYPE, AUTHORIZATION_IMPLICIT);
}
BaseDialogFragmentImpl fragImpl;
OAuthDialogFragment frag;
if (controller.getFragmentManager() instanceof android.support.v4.app.FragmentManager) {
fragImpl = new SupportDialogFragmentImpl();
frag = new OAuthDialogFragment((android.support.v4.app.DialogFragment) fragImpl,
controller.fullScreen, controller.horizontalProgress, controller.hideFullScreenTitle);
if (controller.hideFullScreenTitle) {
if (SDK_INT >= ICE_CREAM_SANDWICH) {
((android.support.v4.app.DialogFragment) fragImpl).setStyle(android.support
.v4.app.DialogFragment.STYLE_NORMAL,
android.R.style.Theme_Holo_Light_NoActionBar_Fullscreen
);
} else {
((android.support.v4.app.DialogFragment) fragImpl).setStyle(android.support
.v4.app.DialogFragment.STYLE_NORMAL,
android.R.style.Theme_Black_NoTitleBar_Fullscreen
);
}
}
} else {
fragImpl = new NativeDialogFragmentImpl();
frag = new OAuthDialogFragment((android.app.DialogFragment) fragImpl,
controller.fullScreen, controller.horizontalProgress, controller.hideFullScreenTitle);
if (controller.hideFullScreenTitle) {
if (SDK_INT >= ICE_CREAM_SANDWICH) {
((android.app.DialogFragment) fragImpl).setStyle(DialogFragment.STYLE_NORMAL,
android.R.style.Theme_Holo_Light_NoActionBar_Fullscreen);
} else {
((android.app.DialogFragment) fragImpl).setStyle(DialogFragment.STYLE_NORMAL,
android.R.style.Theme_Black_NoTitleBar_Fullscreen);
}
}
}
fragImpl.setDialogFragmentCompat(frag);
frag.setArguments(args);
frag.setController(controller);
return frag;
}
示例14: requestAuthorization
import com.google.api.client.auth.oauth2.AuthorizationCodeRequestUrl; //导入依赖的package包/类
/**
* Handles user authorization by redirecting to the OAuth 2.0 authorization
* server as defined in <a
* href="http://tools.ietf.org/html/rfc6749#section-4.1.1">Authorization
* Request</a>.
*
* @param authorizationRequestUrl
*/
void requestAuthorization(AuthorizationCodeRequestUrl authorizationRequestUrl);
示例15: newExplicitAuthorizationUrl
import com.google.api.client.auth.oauth2.AuthorizationCodeRequestUrl; //导入依赖的package包/类
/**
* Returns a new instance of an explicit authorization code request URL.
* <p>
* This is a builder for an authorization web page to allow the end user to
* authorize the application to access their protected resources and that
* returns an authorization code. It uses the
* {@link #getAuthorizationServerEncodedUrl()}, {@link #getClientId()}, and
* {@link #getScopes()}. Sample usage:
* </p>
*
* <pre>
* 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();
* response.sendRedirect(url);
* }
* </pre>
*/
public AuthorizationCodeRequestUrl newExplicitAuthorizationUrl() {
return newAuthorizationUrl();
}