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


Java GoogleCredentials.fromStream方法代码示例

本文整理汇总了Java中com.google.auth.oauth2.GoogleCredentials.fromStream方法的典型用法代码示例。如果您正苦于以下问题:Java GoogleCredentials.fromStream方法的具体用法?Java GoogleCredentials.fromStream怎么用?Java GoogleCredentials.fromStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.auth.oauth2.GoogleCredentials的用法示例。


在下文中一共展示了GoogleCredentials.fromStream方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCredentialsFromFile

import com.google.auth.oauth2.GoogleCredentials; //导入方法依赖的package包/类
public static GoogleCredentials getCredentialsFromFile(String credentialsPath) throws IOException
{
	if (credentialsPath == null || credentialsPath.length() == 0)
		throw new IllegalArgumentException("credentialsPath may not be null or empty");
	GoogleCredentials credentials = null;
	File credentialsFile = new File(credentialsPath);
	if (!credentialsFile.isFile())
	{
		throw new IOException(
				String.format("Error reading credential file %s: File does not exist", credentialsPath));
	}
	try (InputStream credentialsStream = new FileInputStream(credentialsFile))
	{
		credentials = GoogleCredentials.fromStream(credentialsStream, CloudSpannerOAuthUtil.HTTP_TRANSPORT_FACTORY);
	}
	return credentials;
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:18,代码来源:CloudSpannerConnection.java

示例2: initializeFirestore

import com.google.auth.oauth2.GoogleCredentials; //导入方法依赖的package包/类
/**
 * Initializes the Cloud Firestore API with the service account credentials.
 *
 * <p>To performs the initialization successfully, the configuration file
 * {@code serviceAccount.json} should be present in the classpath.
 *
 * @return the initialized instance of {@link Firestore}
 */
public static Firestore initializeFirestore() {
    final InputStream firebaseSecret = FirebaseClients.class
            .getClassLoader()
            .getResourceAsStream(FIREBASE_SERVICE_ACC_SECRET);
    checkNotNull(firebaseSecret,
                 "Required credentials file '%s' does not exist.", FIREBASE_SERVICE_ACC_SECRET);
    final GoogleCredentials credentials;
    try {
        credentials = GoogleCredentials.fromStream(firebaseSecret);
    } catch (IOException e) {
        log().error("Error while reading Firebase config file.", e);
        throw new IllegalStateException(e);
    }
    final FirebaseOptions options = new FirebaseOptions.Builder()
            .setDatabaseUrl(DATABASE_URL)
            .setCredentials(credentials)
            .build();
    FirebaseApp.initializeApp(options);
    final Firestore firestore = FirestoreClient.getFirestore();
    return firestore;
}
 
开发者ID:SpineEventEngine,项目名称:todo-list,代码行数:30,代码来源:FirebaseClients.java

示例3: starting

import com.google.auth.oauth2.GoogleCredentials; //导入方法依赖的package包/类
@Override
public void starting(Description description) {
    if (FirebaseApp.getApps().isEmpty()) {
        final GoogleCredentials credentials;

        try {
            credentials = GoogleCredentials.fromStream(new FileInputStream(SERVICE_ACCOUNT_CREDENTIALS));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        FirebaseOptions firebaseOptions = new FirebaseOptions.Builder()
                .setDatabaseUrl(databaseUrl)
                .setCredentials(credentials)
                .build();
        FirebaseApp.initializeApp(firebaseOptions);

        System.setProperty(SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "DEBUG");
    }
    this.databaseReference = FirebaseDatabase.getInstance().getReferenceFromUrl(databaseUrl);
}
 
开发者ID:firebase,项目名称:geofire-java,代码行数:22,代码来源:GeoFireTestingRule.java

示例4: newCredentials

import com.google.auth.oauth2.GoogleCredentials; //导入方法依赖的package包/类
private static Credentials newCredentials(
    @Nullable InputStream credentialsFile, List<String> authScopes) throws IOException {
  try {
    GoogleCredentials creds =
        credentialsFile == null
            ? GoogleCredentials.getApplicationDefault()
            : GoogleCredentials.fromStream(credentialsFile);
    if (!authScopes.isEmpty()) {
      creds = creds.createScoped(authScopes);
    }
    return creds;
  } catch (IOException e) {
    String message = "Failed to init auth credentials: " + e.getMessage();
    throw new IOException(message, e);
  }
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:17,代码来源:GoogleAuthUtils.java

示例5: jwtTokenCreds

import com.google.auth.oauth2.GoogleCredentials; //导入方法依赖的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());
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:19,代码来源:AbstractInteropTest.java

示例6: oauth2AuthToken

import com.google.auth.oauth2.GoogleCredentials; //导入方法依赖的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

示例7: testNotEquals

import com.google.auth.oauth2.GoogleCredentials; //导入方法依赖的package包/类
@Test
public void testNotEquals() throws IOException {
  GoogleCredentials credentials = GoogleCredentials.fromStream(ServiceAccount.EDITOR.asStream());
  FirebaseOptions options1 =
      new FirebaseOptions.Builder()
          .setCredentials(credentials)
          .build();
  FirebaseOptions options2 =
      new FirebaseOptions.Builder()
          .setCredentials(credentials)
          .setDatabaseUrl("https://test.firebaseio.com")
          .build();
  assertFalse(options1.equals(options2));
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:15,代码来源:FirebaseOptionsTest.java

示例8: getCertCredential

import com.google.auth.oauth2.GoogleCredentials; //导入方法依赖的package包/类
public static GoogleCredentials getCertCredential(InputStream stream) {
  try {
    return GoogleCredentials.fromStream(stream);
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:8,代码来源:TestUtils.java

示例9: googleContainerRegistryAuthSupplier

import com.google.auth.oauth2.GoogleCredentials; //导入方法依赖的package包/类
/**
 * Attempt to load a GCR compatible RegistryAuthSupplier based on a few conditions:
 * <ol>
 * <li>First check to see if the environemnt variable DOCKER_GOOGLE_CREDENTIALS is set and points
 * to a readable file</li>
 * <li>Otherwise check if the Google Application Default Credentials can be loaded</li>
 * </ol>
 * Note that we use a special environment variable of our own in addition to any environment
 * variable that the ADC loading uses (GOOGLE_APPLICATION_CREDENTIALS) in case there is a need for
 * the user to use the latter env var for some other purpose in their build.
 *
 * @return a GCR RegistryAuthSupplier, or null
 * @throws IOException if an IOException occurs while loading the credentials
 */
@Nullable
private RegistryAuthSupplier googleContainerRegistryAuthSupplier() throws IOException {
  GoogleCredentials credentials = null;

  final String googleCredentialsPath = System.getenv("DOCKER_GOOGLE_CREDENTIALS");
  if (googleCredentialsPath != null) {
    final File file = new File(googleCredentialsPath);
    if (file.exists()) {
      try (FileInputStream inputStream = new FileInputStream(file)) {
        credentials = GoogleCredentials.fromStream(inputStream);
        getLog().info("Using Google credentials from file: " + file.getAbsolutePath());
      }
    }
  }

  // use the ADC last
  if (credentials == null) {
    try {
      credentials = GoogleCredentials.getApplicationDefault();
      getLog().info("Using Google application default credentials");
    } catch (IOException ex) {
      // No GCP default credentials available
      getLog().debug("Failed to load Google application default credentials", ex);
    }
  }

  if (credentials == null) {
    return null;
  }

  return ContainerRegistryAuthSupplier.forCredentials(credentials).build();
}
 
开发者ID:spotify,项目名称:dockerfile-maven,代码行数:47,代码来源:AbstractDockerMojo.java

示例10: getCredentials

import com.google.auth.oauth2.GoogleCredentials; //导入方法依赖的package包/类
private Credentials getCredentials(Cloud cloud) {

            Path jsonPath = Paths.get(cloud.getCredential());
            try (InputStream inputStream = Files.newInputStream(jsonPath, READ)) {
                return GoogleCredentials.fromStream(inputStream);
            } catch (IOException e) {
                throw new RuntimeException(String.format(
                        "Failed to read JSON credentials file [%s]",
                        jsonPath.toAbsolutePath().toString()
                ), e);
            }
        }
 
开发者ID:meridor,项目名称:perspective-backend,代码行数:13,代码来源:ApiProviderImpl.java

示例11: loadCredentials

import com.google.auth.oauth2.GoogleCredentials; //导入方法依赖的package包/类
public static GoogleCredentials loadCredentials(S3UploadMetadata uploadMetadata, JsonObjectFileHelper jsonHelper) {
  try {
    if (!uploadMetadata.getGcsCredentials().isEmpty()) {
      return GoogleCredentials.fromStream(jsonHelper.toInputStream(uploadMetadata.getGcsCredentials()));
    }

    // Load from default credentials as determined by GOOGLE_APPLICATION_CREDENTIALS var if none provided in metadata
    return GoogleCredentials.getApplicationDefault();
  } catch (IOException e) {
    throw new RuntimeException("Issue reading credentials file specified in `GOOGLE_APPLICATION_CREDENTIALS`", e);
  }
}
 
开发者ID:HubSpot,项目名称:Singularity,代码行数:13,代码来源:SingularityGCSUploader.java


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