Skip to content

Authentication

Olivier Lefebvre edited this page Feb 21, 2018 · 6 revisions

Oauth2 Access Token

You need a Service account and the its private key file.
Next you can bind this file in an AuthTokenOptions or use Google.Apis.Auth to load it.

Bind to an AuthTokenOptions

{
    "AuthTokenOptions": {
        {
            "type": "service_account",
            "project_id": "the project id",
            "private_key_id": "the private key id",
            "private_key": "-----BEGIN PRIVATE KEY-----
                            
            -----END PRIVATE KEY-----\n",
            "client_email": "the client email",
            "client_id": "the client id",
            "auth_uri": "https://accounts.google.com/o/oauth2/auth",
            "token_uri": "https://accounts.google.com/o/oauth2/token",
            "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
            "client_x509_cert_url": "the cert url"
        }
    }
}

services.AddIdentity<ApplicationUser, IdentityRole>()
    .AddFirebaseStores("http://database url", options =>
    {
        Configuration.GetSection("AuthTokenOptions").Bind(options);
    })
    .AddDefaultTokenProviders();

Load using Google.Apis.Auth

services.AddIdentity<ApplicationUser, IdentityRole>()
    .AddFirebaseStores("http://database url", provider =>
    {
        return GoogleCredential.FromFile("path to the private key file")
            .CreateScoped("https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/firebase.database")
            .UnderlyingCredential;
    });

Firebase Id Token

To use Firebase Id Token, you need to setup a user in your database and activate eMail/Password connection mode (this package support only this connection mode).

eMail/Password

var options = new EmailPasswordOptions();
Configuration.GetSection("EmailPasswordOptions").Bind(options);
services.AddIdentity<ApplicationUser, IdentityRole>()
    .AddFirebaseStores("http://database url", provider =>
    {
        return new EmailPasswordTokenManager(provider.GetRequiredService<HttpClient>(), options);
    })
    .AddDefaultTokenProviders();

Other connection mode

Implement IFirebaseTokenManager interface to use other connection mode and provide your implementation class in DI.

Firebase Docs

Clone this wiki locally