本文整理汇总了Java中io.grpc.auth.MoreCallCredentials类的典型用法代码示例。如果您正苦于以下问题:Java MoreCallCredentials类的具体用法?Java MoreCallCredentials怎么用?Java MoreCallCredentials使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MoreCallCredentials类属于io.grpc.auth包,在下文中一共展示了MoreCallCredentials类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUserDetails
import io.grpc.auth.MoreCallCredentials; //导入依赖的package包/类
private AppsCodeUserDetails getUserDetails(String teamId, String username, String token)
throws Exception {
String email = emailCache.getIfPresent(new UserId(teamId, username));
if (email != null && !email.isEmpty()) {
logger.info(String
.format("Returning user details from cache. username: %s, email: %s", username, email));
return AppsCodeUserDetails.fromUsernameAndEmail(username, email);
}
ConduitGrpc.ConduitBlockingStub conduitBlockingStub = ConduitGrpc.newBlockingStub(channel).
withCallCredentials(
MoreCallCredentials.from(new TokenCredential(teamId, token)));
ConduitWhoAmIResponse response = conduitBlockingStub.whoAmI(VoidRequest.newBuilder().build());
emailCache.put(new UserId(teamId, response.getUser().getUserName()),
response.getUser().getPrimaryEmail());
return AppsCodeUserDetails.fromUsernameAndEmail(response.getUser().getUserName(),
response.getUser().getPrimaryEmail());
}
示例2: fetchAccessToken
import io.grpc.auth.MoreCallCredentials; //导入依赖的package包/类
private void fetchAccessToken() {
ManagedChannel channel = ManagedChannelBuilder.forTarget(HOSTNAME).build();
try {
mApi = EmbeddedAssistantGrpc.newStub(channel)
.withCallCredentials(MoreCallCredentials.from(
Credentials_.fromResource(getApplicationContext(), R.raw.credentials)
));
} catch (IOException|JSONException e) {
Log.e(TAG, "error creating assistant service:", e);
}
for (Listener listener : mListeners) {
listener. onCredentioalSuccess();
}
}
示例3: jwtTokenCreds
import io.grpc.auth.MoreCallCredentials; //导入依赖的package包/类
/** Test JWT-based auth. */
public void jwtTokenCreds(InputStream serviceAccountJson) throws Exception {
final SimpleRequest request = SimpleRequest.newBuilder()
.setResponseType(PayloadType.COMPRESSABLE)
.setResponseSize(314159)
.setPayload(Payload.newBuilder()
.setBody(ByteString.copyFrom(new byte[271828])))
.setFillUsername(true)
.build();
ServiceAccountCredentials credentials = (ServiceAccountCredentials)
GoogleCredentials.fromStream(serviceAccountJson);
TestServiceGrpc.TestServiceBlockingStub stub = blockingStub
.withCallCredentials(MoreCallCredentials.from(credentials));
SimpleResponse response = stub.unaryCall(request);
assertEquals(credentials.getClientEmail(), response.getUsername());
assertEquals(314159, response.getPayload().getBody().size());
}
示例4: oauth2AuthToken
import io.grpc.auth.MoreCallCredentials; //导入依赖的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()));
}
示例5: connect
import io.grpc.auth.MoreCallCredentials; //导入依赖的package包/类
/**
* Initializes the Assistant.
*/
public void connect() {
mAssistantThread = new HandlerThread("assistantThread");
mAssistantThread.start();
mAssistantHandler = new Handler(mAssistantThread.getLooper());
ManagedChannel channel = ManagedChannelBuilder.forTarget(ASSISTANT_API_ENDPOINT).build();
mAssistantService = EmbeddedAssistantGrpc.newStub(channel)
.withCallCredentials(MoreCallCredentials.from(mUserCredentials));
}
示例6: getCallCredentials
import io.grpc.auth.MoreCallCredentials; //导入依赖的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);
}
示例7: newCallCredentials
import io.grpc.auth.MoreCallCredentials; //导入依赖的package包/类
/**
* Create a new {@link CallCredentials} object.
*
* @throws IOException in case the call credentials can't be constructed.
*/
public static CallCredentials newCallCredentials(AuthAndTLSOptions options) throws IOException {
Credentials creds = newCredentials(options);
if (creds != null) {
return MoreCallCredentials.from(creds);
}
return null;
}
示例8: serviceAccountCreds
import io.grpc.auth.MoreCallCredentials; //导入依赖的package包/类
/** Sends a large unary rpc with service account credentials. */
public void serviceAccountCreds(String jsonKey, InputStream credentialsStream, String authScope)
throws Exception {
// cast to ServiceAccountCredentials to double-check the right type of object was created.
GoogleCredentials credentials =
ServiceAccountCredentials.class.cast(GoogleCredentials.fromStream(credentialsStream));
credentials = credentials.createScoped(Arrays.<String>asList(authScope));
TestServiceGrpc.TestServiceBlockingStub stub = blockingStub
.withCallCredentials(MoreCallCredentials.from(credentials));
final SimpleRequest request = SimpleRequest.newBuilder()
.setFillUsername(true)
.setFillOauthScope(true)
.setResponseSize(314159)
.setResponseType(PayloadType.COMPRESSABLE)
.setPayload(Payload.newBuilder()
.setBody(ByteString.copyFrom(new byte[271828])))
.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()));
final SimpleResponse goldenResponse = SimpleResponse.newBuilder()
.setOauthScope(response.getOauthScope())
.setUsername(response.getUsername())
.setPayload(Payload.newBuilder()
.setType(PayloadType.COMPRESSABLE)
.setBody(ByteString.copyFrom(new byte[314159])))
.build();
assertEquals(goldenResponse, response);
}
示例9: computeEngineCreds
import io.grpc.auth.MoreCallCredentials; //导入依赖的package包/类
/** Sends a large unary rpc with compute engine credentials. */
public void computeEngineCreds(String serviceAccount, String oauthScope) throws Exception {
ComputeEngineCredentials credentials = ComputeEngineCredentials.create();
TestServiceGrpc.TestServiceBlockingStub stub = blockingStub
.withCallCredentials(MoreCallCredentials.from(credentials));
final SimpleRequest request = SimpleRequest.newBuilder()
.setFillUsername(true)
.setFillOauthScope(true)
.setResponseSize(314159)
.setResponseType(PayloadType.COMPRESSABLE)
.setPayload(Payload.newBuilder()
.setBody(ByteString.copyFrom(new byte[271828])))
.build();
final SimpleResponse response = stub.unaryCall(request);
assertEquals(serviceAccount, response.getUsername());
assertFalse(response.getOauthScope().isEmpty());
assertTrue("Received oauth scope: " + response.getOauthScope(),
oauthScope.contains(response.getOauthScope()));
final SimpleResponse goldenResponse = SimpleResponse.newBuilder()
.setOauthScope(response.getOauthScope())
.setUsername(response.getUsername())
.setPayload(Payload.newBuilder()
.setType(PayloadType.COMPRESSABLE)
.setBody(ByteString.copyFrom(new byte[314159])))
.build();
assertEquals(goldenResponse, response);
}