0
0

More than 3 years have passed since last update.

Firebase 認証メモ

Posted at

サーバサイド

初期化

ガイド

FileInputStream refreshToken = new FileInputStream("path/to/refreshToken.json");

FirebaseOptions options = new FirebaseOptions.Builder()
    .setCredentials(GoogleCredentials.fromStream(refreshToken))
    .setDatabaseUrl("https://<DATABASE_NAME>.firebaseio.com/")
    .build();

FirebaseApp.initializeApp(options);

トークンの入手方法

firebaseのconsoleのセッティング画面>サービスアカウントより「新しい秘密鍵の生成」

利用

ガイド

// idToken comes from the client app (shown above)
FirebaseToken decodedToken = FirebaseAuth.getInstance().verifyIdToken(idToken);
String uid = decodedToken.getUid();

クライアントサイド

ガイド
ドキュメント auth.signinwithemailandpassword

ログイン

firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
  // Handle Errors here.
  var errorCode = error.code;
  var errorMessage = error.message;
  // ...
}).then((userCredencial: UserCredential | void) => {
  // userCredencial.user でUser利用する
};

トークン付きリクエスト

ドキュメント User.getidtoken

firebase.auth().signInWithEmailAndPassword(email, password).catch(function (error) {
        // Handle Errors here.
    }).then((userCredencial: UserCredential | void) => {
        // https://firebase.google.com/docs/reference/js/firebase.auth.html?hl=ja#usercredential
        if (userCredencial != null) {
              userCredencial.user.getIdToken(true).then((idToken: string) => {
                    // idTokenをリクエストヘッダに含ませてHTTP通信する処理
              }
        }
    });
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0