Java 类com.google.firebase.auth.FirebaseCredentials 实例源码

项目:firebase-admin-java    文件:FirebaseOptionsTest.java   
@Test
public void createOptionsWithFirebaseCredential() throws IOException {
  FirebaseOptions firebaseOptions =
      new FirebaseOptions.Builder()
          .setCredential(FirebaseCredentials.fromCertificate(ServiceAccount.EDITOR.asStream()))
          .build();

  assertNotNull(firebaseOptions.getJsonFactory());
  assertNotNull(firebaseOptions.getHttpTransport());
  assertNull(firebaseOptions.getDatabaseUrl());
  assertNull(firebaseOptions.getStorageBucket());

  GoogleCredentials credentials = firebaseOptions.getCredentials();
  assertNotNull(credentials);
  assertTrue(credentials instanceof ServiceAccountCredentials);
  assertEquals(
      GoogleCredential.fromStream(ServiceAccount.EDITOR.asStream()).getServiceAccountId(),
      ((ServiceAccountCredentials) credentials).getClientEmail());
}
项目:drd    文件:Context.java   
/**
 * Inicializace firebase služby
 */
private void initFirebase() {
    try {
        InputStream serviceAccount = getClass().getResourceAsStream(FIREBASE_CREDENTAILS);

        Map<String, Object> auth = new HashMap<>();
        auth.put("uid", "my_resources");

        FirebaseOptions options = new FirebaseOptions.Builder()
            .setCredential(FirebaseCredentials.fromCertificate(serviceAccount))
            .setDatabaseUrl(FIREBASE_URL)
            .setDatabaseAuthVariableOverride(auth)
            .build();

        FirebaseApp.initializeApp(options);
    } catch (Exception e) {
        logger.info("Nemůžu se připojit k firebase", e);
    }
}
项目:curiostack    文件:FirebaseAuthModule.java   
@Provides
@Singleton
static FirebaseApp firebaseApp(FirebaseAuthConfig config) {
  final FirebaseOptions options;
  try {
    options =
        new FirebaseOptions.Builder()
            .setCredential(
                FirebaseCredentials.fromCertificate(
                    new ByteArrayInputStream(
                        Base64.getDecoder().decode(config.getServiceAccountBase64()))))
            .setDatabaseUrl("https://" + config.getProjectId() + ".firebaseio.com")
            .build();
  } catch (IOException e) {
    throw new UncheckedIOException("Could not read certificate.", e);
  }
  FirebaseApp.initializeApp(options);
  return FirebaseApp.getInstance();
}
项目:members_cuacfm    文件:ApplicationConfig.java   
/**
 * Initialize firebase.
 *
 * @param pathConfig the path config
 * @param atribute the atribute
 * @param pathdefault the pathdefault
 * @return the firebase auth
 */
private static void initializeFirebase(String pathConfig, String atribute, String pathdefault) {
    try {
        File config = new File(pathConfig + properties.getProperty(atribute));
        InputStream serviceAccount;
        if (config.exists()) {
            serviceAccount = new FileInputStream(config);
            logger.info("initializeFirebase outside" + config);
        } else {
            serviceAccount = FileUtils.getFile(pathdefault);
            logger.info("initializeFirebase inside" + pathdefault);
        }
        // Initialize Firebase
        FirebaseOptions options = new FirebaseOptions.Builder().setCredential(FirebaseCredentials.fromCertificate(serviceAccount)).build();
        FirebaseApp.initializeApp(options, "members");
        serviceAccount.close();
    } catch (Exception e) {
        logger.error("initializeFirebase ", e);
    }
}
项目:mxisd    文件:GoogleFirebaseBackend.java   
private FirebaseCredential getCreds(String credsPath) throws IOException {
    if (StringUtils.isNotBlank(credsPath)) {
        return FirebaseCredentials.fromCertificate(new FileInputStream(credsPath));
    } else {
        return FirebaseCredentials.applicationDefault();
    }
}
项目:trvlr-backend    文件:FirebaseService.java   
private FirebaseApp initialize() {
    try (FileInputStream serviceAccount = new FileInputStream(getServiceAccountFilePath())) {
        FirebaseOptions options = new FirebaseOptions.Builder()
                .setCredential(FirebaseCredentials.fromCertificate(serviceAccount))
                .setDatabaseUrl(databaseUrl)
                .build();

        return FirebaseApp.initializeApp(options);
    } catch (IOException e) {
        System.out.println(e.getMessage());
        return null;
    }
}
项目:iosched    文件:FirebaseWrapper.java   
public void initFirebase(String databaseUrl, InputStream serviceAccount) {
    FirebaseOptions options =
            new FirebaseOptions.Builder()
                    .setCredential(FirebaseCredentials.fromCertificate(serviceAccount))
                    .setDatabaseUrl(databaseUrl)
                    .build();

    if (FirebaseApp.getApps().isEmpty()) {
        FirebaseApp.initializeApp(options);
    }
}
项目:iosched    文件:FirebaseWrapper.java   
public String getAccessToken(InputStream serviceAccount) {
    Task<String> tokenTask = FirebaseCredentials.fromCertificate(serviceAccount)
        .getAccessToken(false);
    try {
        Tasks.await(tokenTask);
    } catch (InterruptedException | ExecutionException e) {
        LOG.log(Level.SEVERE, "An error occurred while generating the access token", e);
        return null;
    }
    return tokenTask.getResult();
}