• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java OAuth2Credentials类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: onChanged

import com.google.auth.oauth2.OAuth2Credentials; //导入依赖的package包/类
@Override
public void onChanged(OAuth2Credentials credentials) throws IOException {
  // When this event fires, it is guaranteed that credentials.getAccessToken() will return a
  // valid OAuth2 token.
  final AccessToken accessToken = credentials.getAccessToken();

  // Notify the TokenChangeListener on database's thread pool to make sure that
  // all database work happens on database worker threads.
  executor.execute(
      new Runnable() {
        @Override
        public void run() {
          listener.onTokenChange(wrapOAuthToken(accessToken, authVariable));
        }
      });
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:17,代码来源:JvmAuthTokenProvider.java


示例2: oauth2AuthToken

import com.google.auth.oauth2.OAuth2Credentials; //导入依赖的package包/类
/** Sends a unary rpc with raw oauth2 access token credentials. */
public void oauth2AuthToken(String jsonKey, InputStream credentialsStream, String authScope)
    throws Exception {
  GoogleCredentials utilCredentials =
      GoogleCredentials.fromStream(credentialsStream);
  utilCredentials = utilCredentials.createScoped(Arrays.<String>asList(authScope));
  AccessToken accessToken = utilCredentials.refreshAccessToken();

  OAuth2Credentials credentials = OAuth2Credentials.create(accessToken);

  TestServiceGrpc.TestServiceBlockingStub stub = blockingStub
      .withCallCredentials(MoreCallCredentials.from(credentials));
  final SimpleRequest request = SimpleRequest.newBuilder()
      .setFillUsername(true)
      .setFillOauthScope(true)
      .build();

  final SimpleResponse response = stub.unaryCall(request);
  assertFalse(response.getUsername().isEmpty());
  assertTrue("Received username: " + response.getUsername(),
      jsonKey.contains(response.getUsername()));
  assertFalse(response.getOauthScope().isEmpty());
  assertTrue("Received oauth scope: " + response.getOauthScope(),
      authScope.contains(response.getOauthScope()));
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:26,代码来源:AbstractInteropTest.java


示例3: testWithOAuth2Credential

import com.google.auth.oauth2.OAuth2Credentials; //导入依赖的package包/类
@Test
public void testWithOAuth2Credential() {
  final AccessToken token = new AccessToken("allyourbase", new Date(Long.MAX_VALUE));
  final OAuth2Credentials oAuth2Credentials = new OAuth2Credentials() {
    @Override
    public AccessToken refreshAccessToken() throws IOException {
      return token;
    }
  };
  interceptor = new ClientAuthInterceptor(oAuth2Credentials, executor);
  ClientCall<String, Integer> interceptedCall =
      interceptor.interceptCall(descriptor, CallOptions.DEFAULT, channel);
  Metadata headers = new Metadata();
  interceptedCall.start(listener, headers);
  assertEquals(listener, call.responseListener);
  assertEquals(headers, call.headers);
  Iterable<String> authorization = headers.getAll(AUTHORIZATION);
  Assert.assertArrayEquals(new String[]{"Bearer allyourbase"},
      Iterables.toArray(authorization, String.class));
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:21,代码来源:ClientAuthInterceptorTest.java


示例4: oauth2Credential

import com.google.auth.oauth2.OAuth2Credentials; //导入依赖的package包/类
@Test
public void oauth2Credential() {
  final AccessToken token = new AccessToken("allyourbase", new Date(Long.MAX_VALUE));
  final OAuth2Credentials credentials = new OAuth2Credentials() {
    @Override
    public AccessToken refreshAccessToken() throws IOException {
      return token;
    }
  };

  GoogleAuthLibraryCallCredentials callCredentials =
      new GoogleAuthLibraryCallCredentials(credentials);
  callCredentials.applyRequestMetadata(method, attrs, executor, applier);
  assertEquals(1, runPendingRunnables());

  verify(applier).apply(headersCaptor.capture());
  Metadata headers = headersCaptor.getValue();
  Iterable<String> authorization = headers.getAll(AUTHORIZATION);
  assertArrayEquals(new String[]{"Bearer allyourbase"},
      Iterables.toArray(authorization, String.class));
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:22,代码来源:GoogleAuthLibraryCallCredentialsTest.java


示例5: onChanged

import com.google.auth.oauth2.OAuth2Credentials; //导入依赖的package包/类
@Override
public final synchronized void onChanged(OAuth2Credentials credentials) throws IOException {
  if (state.get() != State.STARTED) {
    return;
  }

  AccessToken accessToken = credentials.getAccessToken();
  long refreshDelay = getRefreshDelay(accessToken);
  if (refreshDelay > 0) {
    scheduleRefresh(refreshDelay);
  } else {
    logger.warn("Token expiry ({}) is less than 5 minutes in the future. Not "
        + "scheduling a proactive refresh.", accessToken.getExpirationTime());
  }
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:16,代码来源:FirebaseApp.java


示例6: testAddCredentialsChangedListenerWithoutInitialToken

import com.google.auth.oauth2.OAuth2Credentials; //导入依赖的package包/类
@Test
public void testAddCredentialsChangedListenerWithoutInitialToken() throws IOException {
  FirebaseApp firebaseApp = FirebaseApp.initializeApp(getMockCredentialOptions(), "myApp");
  CredentialsChangedListener listener = mock(CredentialsChangedListener.class);
  ImplFirebaseTrampolines.getCredentials(firebaseApp).addChangeListener(listener);
  verify(listener, never()).onChanged(Mockito.any(OAuth2Credentials.class));
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:8,代码来源:FirebaseAppTest.java


示例7: testCredentialsChangedListenerOnTokenChange

import com.google.auth.oauth2.OAuth2Credentials; //导入依赖的package包/类
@Test
public void testCredentialsChangedListenerOnTokenChange() throws Exception {
  FirebaseApp firebaseApp = FirebaseApp.initializeApp(getMockCredentialOptions(), "myApp");
  CredentialsChangedListener listener = mock(CredentialsChangedListener.class);
  ImplFirebaseTrampolines.getCredentials(firebaseApp).addChangeListener(listener);

  for (int i = 0; i < 5; i++) {
    TestOnlyImplFirebaseTrampolines.getToken(firebaseApp, true);
    verify(listener, times(i + 1)).onChanged(Mockito.any(OAuth2Credentials.class));
  }
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:12,代码来源:FirebaseAppTest.java


示例8: testCredentialsChangedListenerWithNoRefresh

import com.google.auth.oauth2.OAuth2Credentials; //导入依赖的package包/类
@Test
public void testCredentialsChangedListenerWithNoRefresh() throws Exception {
  FirebaseApp firebaseApp = FirebaseApp.initializeApp(getMockCredentialOptions(), "myApp");
  CredentialsChangedListener listener = mock(CredentialsChangedListener.class);
  ImplFirebaseTrampolines.getCredentials(firebaseApp).addChangeListener(listener);

  TestOnlyImplFirebaseTrampolines.getToken(firebaseApp, true);
  verify(listener, times(1)).onChanged(Mockito.any(OAuth2Credentials.class));

  reset(listener);
  TestOnlyImplFirebaseTrampolines.getToken(firebaseApp, false);
  verify(listener, never()).onChanged(Mockito.any(OAuth2Credentials.class));
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:14,代码来源:FirebaseAppTest.java


示例9: testProactiveTokenRefresh

import com.google.auth.oauth2.OAuth2Credentials; //导入依赖的package包/类
@Test
public void testProactiveTokenRefresh() throws Exception {
  MockTokenRefresherFactory factory = new MockTokenRefresherFactory();
  FirebaseApp firebaseApp = FirebaseApp.initializeApp(getMockCredentialOptions(), "myApp",
      factory);
  MockTokenRefresher tokenRefresher = factory.instance;
  Assert.assertNotNull(tokenRefresher);

  CredentialsChangedListener listener = mock(CredentialsChangedListener.class);
  ImplFirebaseTrampolines.getCredentials(firebaseApp).addChangeListener(listener);

  firebaseApp.startTokenRefresher();

  // Since there was no token to begin with, the refresher should refresh the credential
  // immediately.
  tokenRefresher.simulateDelay(0);
  verify(listener, times(1)).onChanged(Mockito.any(OAuth2Credentials.class));

  tokenRefresher.simulateDelay(55);
  verify(listener, times(2)).onChanged(Mockito.any(OAuth2Credentials.class));

  tokenRefresher.simulateDelay(20);
  verify(listener, times(2)).onChanged(Mockito.any(OAuth2Credentials.class));

  tokenRefresher.simulateDelay(35);
  verify(listener, times(3)).onChanged(Mockito.any(OAuth2Credentials.class));
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:28,代码来源:FirebaseAppTest.java


示例10: testProactiveTokenRefreshWithInitialToken

import com.google.auth.oauth2.OAuth2Credentials; //导入依赖的package包/类
@Test
public void testProactiveTokenRefreshWithInitialToken() throws Exception {
  MockTokenRefresherFactory factory = new MockTokenRefresherFactory();
  FirebaseApp firebaseApp = FirebaseApp.initializeApp(getMockCredentialOptions(), "myApp",
      factory);
  MockTokenRefresher tokenRefresher = factory.instance;
  Assert.assertNotNull(tokenRefresher);

  // Get the initial token
  TestOnlyImplFirebaseTrampolines.getToken(firebaseApp, true);

  CredentialsChangedListener listener = mock(CredentialsChangedListener.class);
  ImplFirebaseTrampolines.getCredentials(firebaseApp).addChangeListener(listener);

  firebaseApp.startTokenRefresher();

  // Since there is already a valid token, which won't expire for another hour, the refresher
  // should not refresh the credential at this point in time.
  tokenRefresher.simulateDelay(0);
  verify(listener, never()).onChanged(Mockito.any(OAuth2Credentials.class));

  tokenRefresher.simulateDelay(55);
  verify(listener, times(1)).onChanged(Mockito.any(OAuth2Credentials.class));

  tokenRefresher.simulateDelay(20);
  verify(listener, times(1)).onChanged(Mockito.any(OAuth2Credentials.class));

  tokenRefresher.simulateDelay(35);
  verify(listener, times(2)).onChanged(Mockito.any(OAuth2Credentials.class));
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:31,代码来源:FirebaseAppTest.java


示例11: getCallCredentials

import com.google.auth.oauth2.OAuth2Credentials; //导入依赖的package包/类
/**
 * Get CallCredentials from OAuthCredentials
 *
 * @param oAuthCredentials the credentials from the AuthenticationHelper
 * @return the CallCredentials for the GRPC requests
 */
private CallCredentials getCallCredentials(OAuthCredentials oAuthCredentials) {

    AccessToken accessToken = new AccessToken(
            oAuthCredentials.getAccessToken(),
            new Date(oAuthCredentials.getExpirationTime())
    );

    OAuth2Credentials oAuth2Credentials = new OAuth2Credentials(accessToken);

    // Create an instance of {@link io.grpc.CallCredentials}
    return MoreCallCredentials.from(oAuth2Credentials);
}
 
开发者ID:mautini,项目名称:google-assistant-java-demo,代码行数:19,代码来源:AssistantClient.java


示例12: createAccessTokenCredentials

import com.google.auth.oauth2.OAuth2Credentials; //导入依赖的package包/类
private Credentials createAccessTokenCredentials(AccessTokenCredentials accessTokenCreds) {
  AccessToken accessToken = new AccessToken(
      readFile(Paths.get(accessTokenCreds.getAccessTokenPath())), null);

  logger.info("Using access token credentials");
  return new OAuth2Credentials(accessToken);
}
 
开发者ID:grpc-ecosystem,项目名称:polyglot,代码行数:8,代码来源:OauthCredentialsFactory.java


示例13: producesAccessTokenCredentials

import com.google.auth.oauth2.OAuth2Credentials; //导入依赖的package包/类
@Test
public void producesAccessTokenCredentials() {
  OauthCredentialsFactory factory = new OauthCredentialsFactory(OauthConfiguration.newBuilder()
      .setAccessTokenCredentials(AccessTokenCredentials.newBuilder()
          .setAccessTokenPath(tempFile.toString()))
      .build());
  assertThat(factory.getCredentials()).isInstanceOf(OAuth2Credentials.class);
}
 
开发者ID:grpc-ecosystem,项目名称:polyglot,代码行数:9,代码来源:OauthCredentialsFactoryTest.java


示例14: onChanged

import com.google.auth.oauth2.OAuth2Credentials; //导入依赖的package包/类
@Override
public void onChanged(OAuth2Credentials credentials) throws IOException {
  count++;
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:5,代码来源:JvmAuthTokenProviderTest.java


示例15: HttpTraceConsumer

import com.google.auth.oauth2.OAuth2Credentials; //导入依赖的package包/类
public HttpTraceConsumer(OAuth2Credentials oAuth2Credentials, String hostUrl) {
  this.oAuth2Credentials = oAuth2Credentials;
  this.hostUrl = hostUrl;
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java,代码行数:5,代码来源:HttpTraceConsumer.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PathBuilder类代码示例发布时间:2022-05-23
下一篇:
Java JsonXMLConfigBuilder类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap