当前位置: 首页>>代码示例>>Java>>正文


Java ClientParametersAuthentication类代码示例

本文整理汇总了Java中com.google.api.client.auth.oauth2.ClientParametersAuthentication的典型用法代码示例。如果您正苦于以下问题:Java ClientParametersAuthentication类的具体用法?Java ClientParametersAuthentication怎么用?Java ClientParametersAuthentication使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ClientParametersAuthentication类属于com.google.api.client.auth.oauth2包,在下文中一共展示了ClientParametersAuthentication类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: authorize

import com.google.api.client.auth.oauth2.ClientParametersAuthentication; //导入依赖的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");
  }
}
 
开发者ID:kmonkeyjam,项目名称:slack-java-client,代码行数:26,代码来源:Auth.java

示例2: new10aTokenRequest

import com.google.api.client.auth.oauth2.ClientParametersAuthentication; //导入依赖的package包/类
/**
 * Returns a new instance of a token request based on the given verifier
 * code. This step is defined in <a
 * href="http://oauth.net/core/1.0a/#auth_step3">Obtaining an Access
 * Token</a>.
 * 
 * @param temporaryCredentials
 * @param verifierCode
 * @return
 */
public OAuthGetAccessToken new10aTokenRequest(OAuthCredentialsResponse temporaryCredentials,
        String verifierCode) {
    OAuthGetAccessToken request = new OAuthGetAccessToken(getTokenServerEncodedUrl());
    request.temporaryToken = temporaryCredentials.token;
    request.transport = getTransport();

    OAuthHmacSigner signer = new OAuthHmacSigner();
    ClientParametersAuthentication clientAuthentication = (ClientParametersAuthentication) getClientAuthentication();
    signer.clientSharedSecret = clientAuthentication.getClientSecret();
    signer.tokenSharedSecret = temporaryCredentials.tokenSecret;

    request.signer = signer;
    request.consumerKey = clientAuthentication.getClientId();
    request.verifier = verifierCode;
    return request;
}
 
开发者ID:agilie,项目名称:dribbble-android-sdk,代码行数:27,代码来源:AuthorizationFlow.java

示例3: new10aCredential

import com.google.api.client.auth.oauth2.ClientParametersAuthentication; //导入依赖的package包/类
/**
 * 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
 */
private OAuthHmacCredential new10aCredential(String userId) {
    ClientParametersAuthentication clientAuthentication = (ClientParametersAuthentication) getClientAuthentication();
    OAuthHmacCredential.Builder builder =
            new OAuthHmacCredential.Builder(getMethod(), clientAuthentication.getClientId(),
                    clientAuthentication.getClientSecret())
                    .setTransport(getTransport())
                    .setJsonFactory(getJsonFactory())
                    .setTokenServerEncodedUrl(getTokenServerEncodedUrl())
                    .setClientAuthentication(getClientAuthentication())
                    .setRequestInitializer(getRequestInitializer())
                    .setClock(getClock());
    if (getCredentialStore() != null) {
        builder.addRefreshListener(
                new CredentialStoreRefreshListener(userId, getCredentialStore()));
    }

    builder.getRefreshListeners().addAll(getRefreshListeners());

    return builder.build();
}
 
开发者ID:agilie,项目名称:dribbble-android-sdk,代码行数:27,代码来源:AuthorizationFlow.java

示例4: Oauth2Helper

import com.google.api.client.auth.oauth2.ClientParametersAuthentication; //导入依赖的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();
//		}
	}
 
开发者ID:RexYing,项目名称:healthy-lifestyle,代码行数:25,代码来源:Oauth2Helper.java

示例5: testGenerateCredential

import com.google.api.client.auth.oauth2.ClientParametersAuthentication; //导入依赖的package包/类
/**
 * Tests generating OAuth2 credentials.
 */
@Test
public void testGenerateCredential() throws Exception {
  HttpTransport httpTransport = new NetHttpTransport();

  OfflineCredentials offlineCredentials = new OfflineCredentials.Builder(oAuth2Helper)
      .forApi(OfflineCredentials.Api.DFP)
      .withClientSecrets("clientId", "clientSecret")
      .withRefreshToken("refreshToken")
      .withHttpTransport(httpTransport)
      .build();

  when(oAuth2Helper.callRefreshToken(Mockito.<Credential>anyObject())).thenReturn(true);

  Credential credential = offlineCredentials.generateCredential();

  assertEquals(
      "clientId",
      ((ClientParametersAuthentication) credential.getClientAuthentication()).getClientId());
  assertEquals(
      "clientSecret",
      ((ClientParametersAuthentication) credential.getClientAuthentication()).getClientSecret());
  assertEquals("refreshToken", credential.getRefreshToken());
  assertSame(httpTransport, credential.getTransport());
}
 
开发者ID:googleads,项目名称:googleads-java-lib,代码行数:28,代码来源:OfflineCredentialsTest.java

示例6: testGenerateCredential_defaultTransport

import com.google.api.client.auth.oauth2.ClientParametersAuthentication; //导入依赖的package包/类
/**
 * Tests generating OAuth2 credentials.
 */
@Test
public void testGenerateCredential_defaultTransport() throws Exception {
  OfflineCredentials offlineCredentials = new OfflineCredentials.Builder(oAuth2Helper)
      .forApi(OfflineCredentials.Api.DFP)
      .withClientSecrets("clientId", "clientSecret")
      .withRefreshToken("refreshToken")
      .build();

  when(oAuth2Helper.callRefreshToken(Mockito.<Credential>anyObject())).thenReturn(true);

  Credential credential = offlineCredentials.generateCredential();

  assertEquals(
      "clientId",
      ((ClientParametersAuthentication) credential.getClientAuthentication()).getClientId());
  assertEquals(
      "clientSecret",
      ((ClientParametersAuthentication) credential.getClientAuthentication()).getClientSecret());
  assertEquals("refreshToken", credential.getRefreshToken());
  assertSame(ForApiBuilder.DEFAULT_HTTP_TRANSPORT, credential.getTransport());
}
 
开发者ID:googleads,项目名称:googleads-java-lib,代码行数:25,代码来源:OfflineCredentialsTest.java

示例7: newInstance

import com.google.api.client.auth.oauth2.ClientParametersAuthentication; //导入依赖的package包/类
public static OAuth newInstance(
  Context context,
  FragmentManager fragmentManager,
  ClientParametersAuthentication client,
  String authorizationRequestUrl,
  String tokenServerUrl,
  final String redirectUri,
  List<String> scopes) {
    return newInstance(context, fragmentManager, client, authorizationRequestUrl, tokenServerUrl, redirectUri, scopes, null);
}
 
开发者ID:derveloper,项目名称:android-sipgateSync,代码行数:11,代码来源:OAuth.java

示例8: authorize

import com.google.api.client.auth.oauth2.ClientParametersAuthentication; //导入依赖的package包/类
/**
 * Authenticates your client application against the Ambiverse API endpoint via the OAuth 2
 * protocol. Your client credentials are read from client_secrets.json on your classpath and
 * exchanged for an API access token, which is stored within the API client throughout your
 * session.
 * @see <a href="https://developers.google.com/api-client-library/python/guide/aaa_client_secrets">Google Client Secrets file format</a>
 * @return Credential object holding your API access token
 * @throws IOException
 */
public static Credential authorize(HttpTransport transport, JsonFactory jsonFactory)
		throws IOException {
	// Read the credentials from the provided client_secrets.json file
	GoogleClientSecrets clientSecrets = null;
	try {
		clientSecrets = GoogleClientSecrets.load(jsonFactory,
			new InputStreamReader(AmbiverseApiClient.class.getClassLoader().getResourceAsStream(CLIENT_SECRETS_FILENAME)));
	} catch (NullPointerException e) {
		logger.severe("Copy src/main/resources/client_secrets_template.json to src/main/resources" + CLIENT_SECRETS_FILENAME + " , " +
									System.lineSeparator() +
									"and make sure to specify your client credentials there.");
		System.exit(1);
	}

	// Request an access token
	TokenResponse response = new ClientCredentialsTokenRequest(
			transport,
			jsonFactory,
			new GenericUrl(clientSecrets.getWeb().getTokenUri()))
					.setClientAuthentication(new ClientParametersAuthentication(
							clientSecrets.getWeb().getClientId(),
							clientSecrets.getWeb().getClientSecret()))
					.execute();
	
	// Return the Credential object
	Credential c = new Credential(BearerToken.authorizationHeaderAccessMethod());
	c.setAccessToken(response.getAccessToken());
	
	return c;
}
 
开发者ID:ambi-verse,项目名称:nlu-api-client-java,代码行数:40,代码来源:AmbiverseApiClient.java

示例9: onCreate

import com.google.api.client.auth.oauth2.ClientParametersAuthentication; //导入依赖的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

示例10: configure

import com.google.api.client.auth.oauth2.ClientParametersAuthentication; //导入依赖的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));
}
 
开发者ID:eclipse,项目名称:che,代码行数:38,代码来源:OAuthAuthenticator.java

示例11: new10aTemporaryTokenRequest

import com.google.api.client.auth.oauth2.ClientParametersAuthentication; //导入依赖的package包/类
/**
 * Returns the response of a Request Token request as defined in <a
 * href="http://oauth.net/core/1.0a/#auth_step1">Obtaining an Unauthorized
 * Request Token</a>.
 * 
 * @param redirectUri the {@code oauth_callback} as defined in <a
 *            href="http://oauth.net/core/1.0a/#rfc.section.6.1.1">Consumer
 *            Obtains a Request Token</a>
 * @return
 * @throws IOException
 */
public OAuthCredentialsResponse new10aTemporaryTokenRequest(String redirectUri)
        throws IOException {
    OAuthGetTemporaryToken temporaryToken =
            new OAuthGetTemporaryToken(getTemporaryTokenRequestUrl());
    OAuthHmacSigner signer = new OAuthHmacSigner();
    ClientParametersAuthentication clientAuthentication = (ClientParametersAuthentication) getClientAuthentication();
    signer.clientSharedSecret = clientAuthentication.getClientSecret();
    temporaryToken.signer = signer;
    temporaryToken.consumerKey = clientAuthentication.getClientId();
    temporaryToken.callback = redirectUri;
    temporaryToken.transport = getTransport();
    return temporaryToken.execute();
}
 
开发者ID:agilie,项目名称:dribbble-android-sdk,代码行数:25,代码来源:AuthorizationFlow.java

示例12: newCredential

import com.google.api.client.auth.oauth2.ClientParametersAuthentication; //导入依赖的package包/类
private static Credential newCredential(String userId, DataStore<StoredCredential> credentialDataStore) {

        Credential.Builder builder = new Credential.Builder(BearerToken.authorizationHeaderAccessMethod())
                .setTransport(HTTP_TRANSPORT).setJsonFactory(JSON_FACTORY)
                .setTokenServerEncodedUrl("https://accounts.google.com/o/oauth2/token")
                .setClientAuthentication(new ClientParametersAuthentication(client_id, client_secret))
                .setRequestInitializer(null).setClock(Clock.SYSTEM);

        builder.addRefreshListener(new DataStoreCredentialRefreshListener(userId, credentialDataStore));

        return builder.build();
    }
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:13,代码来源:GCalGoogleOAuth.java

示例13: newInstance

import com.google.api.client.auth.oauth2.ClientParametersAuthentication; //导入依赖的package包/类
public static OAuth newInstance(Context context,
        FragmentManager fragmentManager,
        ClientParametersAuthentication client,
        String authorizationRequestUrl,
        String tokenServerUrl,
        final String redirectUri,
        List<String> scopes) {
    return newInstance(context, fragmentManager, client,
            authorizationRequestUrl, tokenServerUrl, redirectUri, scopes, null);
}
 
开发者ID:team-mount-ventoux,项目名称:JayPS-AndroidApp,代码行数:11,代码来源:OAuth.java

示例14: GitHubLoader

import com.google.api.client.auth.oauth2.ClientParametersAuthentication; //导入依赖的package包/类
public GitHubLoader(FragmentActivity activity, int since) {
    super(activity);
    this.page = since;
    this.oauth = OAuth.newInstance(activity.getApplicationContext(),
            activity.getSupportFragmentManager(),
            new ClientParametersAuthentication(GitHubConstants.CLIENT_ID,
                    GitHubConstants.CLIENT_SECRET),
            GitHubConstants.AUTHORIZATION_CODE_SERVER_URL,
            GitHubConstants.TOKEN_SERVER_URL,
            GitHubConstants.REDIRECT_URL,
            Lists.<String> newArrayList());
}
 
开发者ID:wuman,项目名称:android-oauth-client,代码行数:13,代码来源:GitHubActivity.java

示例15: TwitterLoader

import com.google.api.client.auth.oauth2.ClientParametersAuthentication; //导入依赖的package包/类
public TwitterLoader(FragmentActivity activity, String nextMaxId) {
    super(activity);
    this.nextMaxId = nextMaxId;
    oauth = OAuth.newInstance(activity.getApplicationContext(),
            activity.getSupportFragmentManager(),
            new ClientParametersAuthentication(TwitterConstants.CONSUMER_KEY,
                    TwitterConstants.CONSUMER_SECRET),
            TwitterConstants.AUTHORIZATION_VERIFIER_SERVER_URL,
            TwitterConstants.TOKEN_SERVER_URL,
            TwitterConstants.REDIRECT_URL,
            Lists.<String> newArrayList(),
            TwitterConstants.TEMPORARY_TOKEN_REQUEST_URL);
}
 
开发者ID:wuman,项目名称:android-oauth-client,代码行数:14,代码来源:TwitterActivity.java


注:本文中的com.google.api.client.auth.oauth2.ClientParametersAuthentication类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。