本文整理汇总了Java中com.google.api.client.auth.oauth2.AuthorizationCodeFlow类的典型用法代码示例。如果您正苦于以下问题:Java AuthorizationCodeFlow类的具体用法?Java AuthorizationCodeFlow怎么用?Java AuthorizationCodeFlow使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AuthorizationCodeFlow类属于com.google.api.client.auth.oauth2包,在下文中一共展示了AuthorizationCodeFlow类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildCodeFlow
import com.google.api.client.auth.oauth2.AuthorizationCodeFlow; //导入依赖的package包/类
/**
* Gets the credentials stored in GAE. If expired, uses the refresh token to
* get a new access token from OAuth
* @return
* @throws IOException
*/
// START:flow
public static AuthorizationCodeFlow buildCodeFlow()
throws IOException
{
return new GoogleAuthorizationCodeFlow.Builder(
new UrlFetchTransport(),
new JacksonFactory(),
WEB_CLIENT_ID,
WEB_CLIENT_SECRET,
SCOPES)
.setApprovalPrompt( "force" )
.setAccessType("offline")
.setCredentialDataStore( getDataStore() )
.build();
}
示例2: authorizationRequestUri
import com.google.api.client.auth.oauth2.AuthorizationCodeFlow; //导入依赖的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: getService
import com.google.api.client.auth.oauth2.AuthorizationCodeFlow; //导入依赖的package包/类
/**
* Returns an authorized Bitbucket API service.
* @param authorizationCode authorization code received by the redirection
* endpoint
* @return authorized Bitbucket API service
* @throws IOException if an I/O exception has occurred
* @throws NullPointerException if this object has no client credentials
* @since 5.0
*/
public Service getService(String authorizationCode)
throws IOException {
AuthorizationCodeFlow flow = getAuthorizationCodeFlow(true);
AuthorizationCodeTokenRequest request
= flow.newTokenRequest(authorizationCode);
if (redirectionEndpointUri != null) {
request.setRedirectUri(redirectionEndpointUri);
}
TokenResponse tokenResponse = request.execute();
String tokenType = tokenResponse.getTokenType();
if (!tokenType.equals(BEARER_TOKEN_TYPE)) {
throw new UnknownServiceException("Unsupported token type");
}
return new RestService(
flow.createAndStoreCredential(tokenResponse, getUser()));
}
示例4: getAuthorizationCodeFlow
import com.google.api.client.auth.oauth2.AuthorizationCodeFlow; //导入依赖的package包/类
/**
* Returns a authorization code flow for OAuth requests.
* @param forTokenRequest <code>true</code> for token requests, or
* <code>false</code> for authorization requests
* @return {@link AuthorizationCodeFlow} object
* @throws NullPointerException if this object has no client credentials
*/
protected AuthorizationCodeFlow getAuthorizationCodeFlow(
boolean forTokenRequest) {
if (!isConfiguredForOAuth()) {
throw new NullPointerException("No OAuth client credentials");
}
HttpExecuteInterceptor clientAuthenticator;
if (forTokenRequest) {
clientAuthenticator = getBasicAuthentication();
} else {
clientAuthenticator = getClientParameters();
}
return new AuthorizationCodeFlow(
BearerToken.authorizationHeaderAccessMethod(),
getHttpTransport(), JacksonFactory.getDefaultInstance(),
new GenericUrl(TOKEN_ENDPOINT_URI), clientAuthenticator,
getClientId(), AUTHORIZATION_ENDPOINT_URI);
}
示例5: testAuthorizationCodeFlow
import com.google.api.client.auth.oauth2.AuthorizationCodeFlow; //导入依赖的package包/类
@Ignore
@Test
public void testAuthorizationCodeFlow() throws IOException {
OAuthClient client = new OAuthClient();
AuthorizationCodeFlow flow1 = client.getAuthorizationCodeFlow(false);
assertNull(flow1);
AuthorizationCodeFlow flow2 = client.getAuthorizationCodeFlow(true);
assertNull(flow2);
client.setClientId(CLIENT_ID);
client.setClientSecret(CLIENT_SECRET);
AuthorizationCodeFlow flow3 = client.getAuthorizationCodeFlow(false);
assertNotNull(flow3);
String authorizationURL = flow3.newAuthorizationUrl().build();
assertNotNull(authorizationURL);
AuthorizationCodeFlow flow4 = client.getAuthorizationCodeFlow(true);
assertNotNull(flow4);
}
示例6: authorize
import com.google.api.client.auth.oauth2.AuthorizationCodeFlow; //导入依赖的package包/类
public static Credential authorize() throws Exception {
InputStream in = Auth.class.getResourceAsStream("/slack_client_secret.json");
ClientSecrets secrets = objectMapper.readValue(in, ClientSecrets.class);
// set up authorization code flow
AuthorizationCodeFlow flow = new AuthorizationCodeFlow.Builder(BearerToken
.authorizationHeaderAccessMethod(),
HTTP_TRANSPORT,
JSON_FACTORY,
new GenericUrl(TOKEN_SERVER_URL),
new ClientParametersAuthentication(
secrets.getClient_id(), secrets.getClient_secret()),
secrets.getClient_id(),
AUTHORIZATION_SERVER_URL).setScopes(Arrays.asList(SCOPE))
.setDataStoreFactory(DATA_STORE_FACTORY).build();
LocalServerReceiver receiver = new LocalServerReceiver.Builder().setHost(
secrets.getDomain()).setPort(secrets.getPort()).build();
System.out.println("Credentials saved to " + DATA_STORE_DIR.getAbsolutePath());
Credential credential = flow.loadCredential("user");
if (credential != null) {
return credential;
} else {
return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
}
}
示例7: newAuthorizationCodeFlow
import com.google.api.client.auth.oauth2.AuthorizationCodeFlow; //导入依赖的package包/类
/**
* Creates and returns a new {@link AuthorizationCodeFlow} for this app.
*/
public static AuthorizationCodeFlow newAuthorizationCodeFlow() throws IOException {
URL resource = AuthUtil.class.getResource("/oauth.properties");
File propertiesFile = new File("./src/main/resources/oauth.properties");
try {
propertiesFile = new File(resource.toURI());
//LOG.info("Able to find oauth properties from file.");
} catch (URISyntaxException e) {
LOG.info(e.toString());
LOG.info("Using default source path.");
}
FileInputStream authPropertiesStream = new FileInputStream(propertiesFile);
Properties authProperties = new Properties();
authProperties.load(authPropertiesStream);
String clientId = authProperties.getProperty("client_id");
String clientSecret = authProperties.getProperty("client_secret");
return new GoogleAuthorizationCodeFlow.Builder(new NetHttpTransport(), new JacksonFactory(),
clientId, clientSecret, Collections.singleton(GLASS_SCOPE)).setAccessType("offline")
.setCredentialStore(store).build();
}
示例8: Oauth2Helper
import com.google.api.client.auth.oauth2.AuthorizationCodeFlow; //导入依赖的package包/类
public Oauth2Helper(SharedPreferences sharedPreferences, Oauth2Params oauth2Params) {
this.credentialStore = new SharedPreferencesCredentialStore(sharedPreferences);
this.oauth2Params = oauth2Params;
this.flow = new AuthorizationCodeFlow.Builder(oauth2Params.getAccessMethod() ,
HTTP_TRANSPORT,
JSON_FACTORY,
new GenericUrl(oauth2Params.getTokenServerUrl()),
new ClientParametersAuthentication(oauth2Params.getClientId(),
oauth2Params.getClientSecret()),
oauth2Params.getClientId(),
oauth2Params.getAuthorizationServerEncodedUrl()).setCredentialStore(this.credentialStore).build();
// try {
// GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
// new InputStreamReader(Oauth2Helper.class.getResourceAsStream("/client_secrets.json")));
//
// this.flow = new GoogleAuthorizationCodeFlow.Builder(
// HTTP_TRANSPORT, JSON_FACTORY, clientSecrets,
// Collections.singleton(PlusScopes.PLUS_ME)).setCredentialStore(credentialStore).build();
// } catch (Exception ex) {
// ex.printStackTrace();
// }
}
示例9: newFlow
import com.google.api.client.auth.oauth2.AuthorizationCodeFlow; //导入依赖的package包/类
static AuthorizationCodeFlow newFlow() throws IOException {
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JacksonFactory.getDefaultInstance(),
new InputStreamReader(Shared.class.getResourceAsStream("tokens.json")));
return new GoogleAuthorizationCodeFlow.Builder(
new NetHttpTransport(),
JacksonFactory.getDefaultInstance(),
clientSecrets,
Arrays.asList("https://www.googleapis.com/auth/userinfo.email;https://www.googleapis.com/auth/userinfo.profile".split(";"))
)//.setDataStoreFactory(MemoryDataStoreFactory.getDefaultInstance()).setAccessType("offline")
.build();
}
示例10: HtmlUnitAuthorizationCodeInstalledApp
import com.google.api.client.auth.oauth2.AuthorizationCodeFlow; //导入依赖的package包/类
public HtmlUnitAuthorizationCodeInstalledApp(AuthorizationCodeFlow flow, VerificationCodeReceiver receiver,
IProgressMonitor monitor, String userName, String password, Optional<String> recoveryEmail) {
super(flow, receiver);
this.monitor = monitor;
this.userName = userName;
this.password = password;
this.recoveryEmail = recoveryEmail;
}
示例11: get
import com.google.api.client.auth.oauth2.AuthorizationCodeFlow; //导入依赖的package包/类
@Override
public AuthorizationCodeInstalledApp get(AuthorizationCodeFlow flow, VerificationCodeReceiver receiver,
IProgressMonitor monitor) {
HtmlUnitAuthorizationCodeInstalledApp app = new HtmlUnitAuthorizationCodeInstalledApp(flow, receiver,
monitor, userName, password, recoveryEmail);
if (authorizationListener != null) {
app.setAuthorizationListener(authorizationListener);
}
return app;
}
示例12: onCreate
import com.google.api.client.auth.oauth2.AuthorizationCodeFlow; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_authenticator);
accountManager = AccountManager.get(getBaseContext());
try {
flow = new AuthorizationCodeFlow.Builder(
BearerToken.authorizationHeaderAccessMethod(),
HTTP_TRANSPORT,
JSON_FACTORY,
new GenericUrl(TOKEN_SERVER_URL),
new ClientParametersAuthentication(API_KEY, API_SECRET),
API_KEY,
AUTHORIZATION_SERVER_URL)
.setScopes(Arrays.asList(SCOPES))
.setDataStoreFactory(DATA_STORE_FACTORY)
//.setDataStoreFactory(DATA_STORE_FACTORY)
.build();
if (!isRedirect(getIntent())) {
String authorizationUrl = flow.newAuthorizationUrl().setRedirectUri(REDIRECT_URI).build();
// Open the login page in the native browser
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(authorizationUrl));
startActivity(browserIntent);
}
} catch (Exception ex) {
Log.e("auth0test", ex.getMessage());
}
}
开发者ID:pieterderycke,项目名称:AndroidAccountManagerOpenidConnect,代码行数:33,代码来源:SampleAuthenticatorActivity.java
示例13: configure
import com.google.api.client.auth.oauth2.AuthorizationCodeFlow; //导入依赖的package包/类
/**
* This method should be invoked by child class for initialization default instance of {@link
* AuthorizationCodeFlow} that will be used for authorization
*/
protected void configure(
String clientId,
String clientSecret,
String[] redirectUris,
String authUri,
String tokenUri,
MemoryDataStoreFactory dataStoreFactory,
List<String> scopes)
throws IOException {
final AuthorizationCodeFlow authorizationFlow =
new AuthorizationCodeFlow.Builder(
BearerToken.authorizationHeaderAccessMethod(),
new NetHttpTransport(),
new JacksonFactory(),
new GenericUrl(tokenUri),
new ClientParametersAuthentication(clientId, clientSecret),
clientId,
authUri)
.setDataStoreFactory(dataStoreFactory)
.setScopes(scopes)
.build();
LOG.debug(
"clientId={}, clientSecret={}, redirectUris={} , authUri={}, tokenUri={}, dataStoreFactory={}",
clientId,
clientSecret,
redirectUris,
authUri,
tokenUri,
dataStoreFactory);
configure(authorizationFlow, Arrays.asList(redirectUris));
}
示例14: doAuth
import com.google.api.client.auth.oauth2.AuthorizationCodeFlow; //导入依赖的package包/类
private String doAuth(HttpServletRequest req)
throws IOException
{
String authCode = req.getParameter( "code" );
String callbackUri = AuthUtils.fullUrl( req, AuthUtils.OAUTH2_PATH );
// We need a flow no matter what to either redirect or extract information
AuthorizationCodeFlow flow = AuthUtils.buildCodeFlow();
// Without a response code, redirect to Google's authorization URI
if( authCode == null ) {
return flow.newAuthorizationUrl().setRedirectUri( callbackUri ).build();
}
// With a response code, store the user's credential, and
// set the user's ID into the session
GoogleTokenResponse tokenRes = getTokenRes( flow, authCode, callbackUri );
// Extract the Google user ID from the ID token in the auth response
String userId = getUserId( tokenRes );
// Store the user if for the session
SessionUtils.setUserId( req, userId );
// Store the credential with the user
flow.createAndStoreCredential( tokenRes, userId );
return "/";
}
示例15: getTokenRes
import com.google.api.client.auth.oauth2.AuthorizationCodeFlow; //导入依赖的package包/类
/**
* Makes a remote call to the Google Auth server to authorize the grant code,
* in order to issue a request token.
* @param flow
* @param code
* @param callbackUri
* @return
* @throws IOException
*/
private GoogleTokenResponse getTokenRes( AuthorizationCodeFlow flow, String code, String callbackUri )
throws IOException
{
AuthorizationCodeTokenRequest tokenReq = flow
.newTokenRequest( code )
.setRedirectUri( callbackUri );
TokenResponse tokenRes = tokenReq.execute();
return (GoogleTokenResponse)tokenRes;
}