LoginSignup
4
6

More than 5 years have passed since last update.

[翻訳] Firebase Authentication / Users in Firebase Projects

Last updated at Posted at 2016-08-18

Users in Firebase Projectsを翻訳してみました。
お気づきの点があればコメント頂ければと思います。

以下、関連する投稿へのリンクです。
Firebase Authentication / Introduction
Firebase Authentication / Users in Firebase Projects
Firebase Authentication / Android / Manage Users
Firebase Authentication / Android / Password Authentication
Firebase Authentication / Android / Google Sign-In
Firebase Authentication / Android / Anonymous Authentication

Users in Firebase Projects

A Firebase User object represents the account of a user who has signed up to an app in your Firebase project. Apps usually have many registered users, and every app in a Firebase project shares a user database.

A Firebase User instance is independent from a Firebase Auth instance. This means that you can have several references to different users within the same context and still call any of their methods.

Firebase Userオブジェクトは、あなたのFirebaseプロジェクトのアプリにサインアップしたユーザーのアカウントを表します。 アプリには通常多くの登録ユーザーがおり、そしてFirebaseプロジェクト内の各アプリはユーザーデータベースを共有しています。

Firebase UserインスタンスはFirebase Authインスタンスに依存しません。 これはあなたが同一コンテキスト内で異なるユーザーへの複数の参照を持て、彼らのメソッドを呼び出せることを意味します。

User properties

A Firebase User has a fixed set of basic properties—a unique ID, a primary email address, a name and a photo URL—stored in the project's user database, that can be updated by the user (iOS, Android, web). You cannot add other properties to the Firebase User object directly; instead, you can store the additional properties in your Firebase Realtime Database.

The first time a user signs up to your app, the user's profile data is populated using the available information:

  • If the user signed up with an email address and password, only the primary email address property is populated

  • If the user signed up with a federated identity provider, such as Google or Facebook, the account information made available by the provider is used to populate the Firebase User's profile

  • If the user signed up with your custom auth system, you must explicitly add the information you want to the Firebase User's profile

Once a user account has been created, you can reload the user's information to incorporate any changes the user might have made on another device.

Firebase Userはプロジェクトのユーザーデータベースに保存された基本的なプロパティのセット(ユニークID、プライマリメールアドレス、名前、写真のURL)を持っており、それはユーザーが更新できます。(iOS, Android, web) あなたはFirebase Userオブジェクトに直接ほかのプロパティを追加することは出来ません。 その代わりに、Firebase Realtime Databaseに追加のプロパティを保存することができます。

初めてユーザーがあなたのアプリにサインアップしたとき、利用可能な情報を使用してユーザーのプロフィールデータが追加されます:

  • ユーザーが電子メールアドレスとパスワードでサインアップした場合、プライマリメールアドレスだけが追加されます。

  • ユーザーがGoogleやFacebookのようなアイデンティティ・プロバイダでサインアップした場合、プロバイダによって利用可能になったアカウント情報が、Firebaseユーザープロフィールに追加されます。

  • ユーザーがカスタム認証システムでサインアップした場合、あなたはFirebaseユーザープロフィールに使う情報を明示的に追加しなければなりません。

いったんユーザーアカウントが作成されると、あなたはユーザーが他のデバイスで行ったかもしれないすべての変更を取込むため、ユーザー情報をリロードできます。

Sign-in providers

You can sign in users to your Firebase apps using several methods: email address and password, federated identity providers, and your custom auth system. You can associate more than one sign-in method with a user: for example, a user can sign in to the same account using an email address and a password, or using Google Sign-In.

A Firebase User instance keeps track of every provider linked to the user. This allows you to update empty profile's properties using the information given by a provider. See Managing Users (iOS, Android, web).

あなたはいくつかの方法でFirebase アプリにユーザーをサインインさせることができます:メールアドレスとパスワード、アイデンティティ・プロバイダ、およびカスタム認証システムです。 あなたは、一人のユーザーと一つ以上のサインイン方法を関連付けることができます:例えば、一人のユーザーはメールアドレスとパスワード、またはGoogleサインインを使用して同一のアカウントにサインイン出来ます。

Firebase Userインスタンスはユーザーにリンクされているすべてのプロバイダを追跡し続けます。 これにより、プロバイダによって得られた情報を使用して、空のプロフィールのプロパティを更新することが出来ます。 ユーザーの管理を参照してください(iOS, Android, web)

The current user

When a user signs up or signs in, that user becomes the current user of the Auth instance. The Firebase Auth instance persists the user's state, so that refreshing the page (in a browser) or restarting the application doesn't lose the user's information.

When the user signs out, the Auth instance stops keeping a reference to the User object and no longer persists its state; there is no current user. However, the user instance continues to be completely functional: if you keep a reference to it, you can still access and update the user's data.

ユーザーがサインアップまたはサインインした時、そのユーザーがAuthインスタンスの現在のユーザーになります。 Firebase Authインスタンスは、(ブラウザの)ページの更新やアプリの再起動でユーザー情報を失わないようにするため、ユーザーのステートを維持します。

ユーザーがサインアウトした時、AuthインスタンスはUserオブジェクトへの参照の保持をやめ、もはやそのステートを維持しません;現在のユーザーはいません。 しかし、userインスタンスは完全に機能し続けます;もしあなたがそのインスタンスへの参照を持っていれば、あなたは引き続きユーザーデータへのアクセスと更新が出来ます。

The user lifecycle

The recommended way to track the current state of the Firebase Auth instance is by using listeners (also called "observers" in JavaScript). An Auth listener gets notified any time something relevant happens to the Auth object. See Managing Users (iOS, Android, web).

An auth listener gets notified in the following situations:

  • The Auth object finishes initializing and a user was already signed in from a previous session, or has been redirected from an identity provider's sign-in flow

  • A user signs in (the current user is set)

  • A user signs out (the current user becomes null)

  • The current user's access token is refreshed. This case can happen in the following conditions:

    • The access token expires: this is a common situation. The refresh token is used to get a new valid set of tokens.

    • The user changes his password: Firebase issues new access and refresh tokens and renders the old tokens expired. This automatically signs out the user on every device, for security reasons

    • The user re-authenticates: some actions require that the user's credentials are recently issued; such actions include deleting an account, setting a primary email address, and changing a password. Instead of signing out the user and then signing in the user again, get new credentials from the user, and pass the new credentials to the reauthenticate method of the User object.

Firebase Authインスタンスの現在のステートを追跡するための推奨される方法は、リスナー(JavaScriptではオブザーバー)を使うことです。 AuthリスナーはAuthオブジェクトに関する何かが発生したときは常に通知を受けます。 Managing Usersを参照してください (iOS, Android, web).

authリスナーは次のような状況で通知を受けます:

  • Authオブジェクトが初期化を完了し、ユーザーが以前のセッションからすでにサインイン済か、またはアイデンティティ・プロバイダのサインイン フローからリダイレクトされた。

  • ユーザーがサインイン(現在のユーザーがセットされる)

  • ユーザーがサインアウト(現在のユーザーはnullになる)

  • 現在のユーザーのアクセストークンが更新された。このケースは以下の条件で発生する可能性があります:

    • アクセストークンの期限切れ:これは一般的な状況です。 リフレッシュされたトークンが、新しい有効なトークンのセットに使用されます。

    • ユーザーが自身のパスワードを変更:Firebaseは新しいアクセス権を発行し、トークンをリフレッシュし、古いトークンを期限切れにします。 これはセキュリティ上の理由により、自動ですべてのデバイスからユーザーをサインアウトさせます。

    • ユーザーの再認証:いくつかのアクションは、最近発行されたユーザーの証明を必要とします;アカウントの削除や、プライマリメールアドレスの設定や、パスワード変更などを含むアクションです。 ユーザーがサインアウトして再度サインインする代わりに、新しい証明をユーザーから取得します。 そしてUserオブジェクトの再認証メソッドに新しい証明を渡します。

Auth tokens

When you perform authentication with Firebase, there are three kinds of auth tokens you might encounter:

Firebase ID tokens Created by Firebase when a user signs in to a Firebase app. These tokens are signed JWTs that securely identify a user in a Firebase project. These tokens contain basic profile information for a user, including the user's ID string, which is unique to the Firebase project. Because the integrity of ID tokens can be verified, you can send them to a backend server to identify the currently signed-in user.
Identity provider tokens Created by federated identity providers, such as Google and Facebook. These tokens can have different formats, but are often OAuth 2.0 access tokens. Firebase apps use these tokens to verify that users have successfully authenticated with the identity provider, and then convert them into credentials usable by Firebase services.
Firebase custom tokens Created by your custom auth system to allow users to sign in to a Firebase app using your auth system. Custom tokens are JWTs signed using a service account's private key. Firebase apps use these tokens much like they use the tokens returned from federated identity providers.

Firebaseで認証を行う時、あなたが遭遇するかもしれないauthトークンが3種類あります:

Firebase ID tokens ユーザーがFirebaseアプリにサインインしたときにFirebaseが作成。 これらのトークンは確実にFirebaseプロジェクトで身元確認された署名されたJWTです。 これらのトークンはFirebaseプロジェクトでユニークなユーザーIDを含むユーザーの基本的なプロフィール情報を含みます。 IDトークンの整合性が検証されているので、あなたは現在のサインインユーザーを識別するためそれをバックエンドサーバーに送信することができます。
Identity provider tokens GoogleやFacebookなどのアイデンティティ・プロバイダが作成。 これらのトークンはそれぞれフォーマットが異なりますが、多くの場合はOAuth2.0アクセストークンです。 Firebaseアプリはユーザーがアイデンティティ・プロバイダでの認証に成功したかどうかを検証するためにこれらのトークンを使用し、その後それらをFirebaseサービスで利用可能な証明にコンバートします。
Firebase custom tokens ユーザーにあなたの認証システムを使用してFirebaseアプリにサインインさせるため、あなたのカスタム認証システムが作成。 カスタムトークンは、サービスアカウントの秘密鍵を使って署名されたJWTです。 Firebaseアプリは、アイデンティティ・プロバイダから返されたトークンと同じようにこれらのトークンを使用します。
4
6
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
4
6