Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
a232720
Upgraded to VS2017
Apr 10, 2017
c35057c
FirebaseAuthLink accepts IFirebaseAuthProvider instead of FirebaseAut…
Apr 11, 2017
99ea92e
EmailAndPassword has enumMember value email
Apr 13, 2017
48dc640
Bumped version
Apr 13, 2017
8fedc5a
Account already linked error reason
Apr 16, 2017
1f41056
Update README.md
bezysoftware Apr 19, 2017
fcf5d4b
DeleteUser method added to FirebaseAuthProvider
luccasclezar Apr 19, 2017
d90b593
Added UserNotFound Error
luccasclezar Apr 19, 2017
37dd66f
Escaped the quotes in the content string :P
luccasclezar Apr 19, 2017
7b6e091
Wrapped the idToken with quotes :|
luccasclezar Apr 19, 2017
b1af6e4
Added break in the UserNotFound case
luccasclezar Apr 20, 2017
5165567
EmailAndPassword EnumMember is password
Apr 21, 2017
8d0dd30
Merge branch 'master' of https://github.com/step-up-labs/firebase-aut…
Apr 21, 2017
88dd730
Merge pull request #27 from luccasclezar/deleteuser-pr
bezysoftware Jun 25, 2017
e66ac90
Update Firebase.Auth.csproj
bezysoftware Dec 14, 2017
f132186
Delete added to interface
Firedragonweb Feb 17, 2018
f6c884c
Merge pull request #47 from Firedragonweb/interface_additions
bezysoftware Feb 20, 2018
9b643fe
added phone number to User DTO (Authenticate with a PhoneNumber)
sergeylopatyuk Apr 3, 2018
2dcc039
Merge pull request #54 from sergeylopatyuk/master
bezysoftware Apr 4, 2018
7319ad2
Update Firebase.Auth.csproj
bezysoftware Apr 4, 2018
1b52c8b
Rename DeleteUser method
Sep 21, 2018
bb7b5cd
Updated packages
Oct 2, 2018
90becb8
Use .ConfigureAwait(false) where possible
Oct 2, 2018
777f618
Add public API to unlink providers
cabauman Oct 11, 2018
1824e34
Add method to sign in with Google ID token
cabauman Oct 11, 2018
62a59f2
Merge pull request #72 from cabauman/colt_googleIdToken
bezysoftware Oct 12, 2018
f865619
Merge pull request #71 from cabauman/master
bezysoftware Oct 12, 2018
4885072
Update Firebase.Auth.csproj
bezysoftware Oct 13, 2018
f45f530
Add method to update displayName and photoUrl
cabauman Oct 15, 2018
a2be7f1
Merge pull request #73 from cabauman/colt_updateProfile
bezysoftware Dec 7, 2018
9141eff
Update Firebase.Auth.csproj
bezysoftware Dec 7, 2018
895b56e
Add handling of exception for GetUserAsync method.
sergeylopatyuk Jul 23, 2019
db84b89
Remove unused reference
sergeylopatyuk Jul 23, 2019
ec2bb58
Merge branch 'master' into master
sergeylopatyuk Jul 29, 2019
85edc39
Add configureawait for the asynchronous operations
sergeylopatyuk Jul 29, 2019
ed86e04
Merge pull request #88 from sergeylopatyuk/master
bezysoftware Jul 29, 2019
4228145
Update FirebaseAuthProvider.cs
HeavyMachineGun Sep 8, 2019
28254a5
Merge pull request #92 from HeavyMachineGun/master
bezysoftware Sep 14, 2019
f66457b
Update Firebase.Auth.csproj
bezysoftware Sep 14, 2019
e6f37cc
Create stale.yml
bezysoftware Oct 3, 2019
1ebbcb9
Update stale.yml
bezysoftware Oct 3, 2019
8ec415b
Target .net core 3, updated packages
Oct 3, 2019
1e05553
Update stale.yml
bezysoftware Oct 4, 2019
f246b97
Updated test project to .net core 3
Nov 22, 2019
a77e90f
Added SignInWithOAuthTwitterTokenAsync
blemasle Nov 25, 2019
48fa002
Looking for exception reason on reset password
blemasle Nov 25, 2019
b956e76
Added more AuthErrorReason
blemasle Nov 25, 2019
1f71d23
Improved error detection reliability
blemasle Nov 25, 2019
2db2187
Fixed indent style
blemasle Nov 27, 2019
d564761
Merge pull request #97 from blemasle/master
bezysoftware Nov 27, 2019
214f43d
Update Firebase.Auth.csproj
bezysoftware Nov 27, 2019
2df431a
Merge branch 'master' of github.com:step-up-labs/firebase-authenticat…
Dec 2, 2019
ccd1cd2
Create dotnetcore.yml
bezysoftware Dec 27, 2019
f75ec11
Update README.md
bezysoftware Jan 11, 2020
fc2d811
Add multi-tenancy to signin with email and password (#113)
mohed May 1, 2020
f776c9f
fetch user details after each successful sign in (#112)
itswisdomagain Jan 30, 2021
8fcb3be
Removed duplicate curly brace (#136)
sheindel Feb 19, 2021
f21c952
Enable Apple Sign In (#140)
Kapusch Apr 2, 2021
811765a
add method to updates User email (#132)
Luizfelipefm Apr 6, 2021
d08ea7c
Bump version
bezysoftware Apr 6, 2021
36643f7
Added option to specify locale of sent email. (#156)
badochov Aug 5, 2021
7fc2859
Update Firebase.Auth.csproj
bezysoftware Aug 5, 2021
a084edf
Full rewrite with FirebaseUI (#180)
bezysoftware Jan 4, 2023
f972ba9
Feature/v4 (#184)
bezysoftware Jan 8, 2023
419936f
fix: unknown FirebaseProviderType
bezysoftware Feb 5, 2023
f0d02ee
Bump tests to net6
bezysoftware Sep 6, 2023
0dd924b
Added Auth.UI.WinUI3 and WinUI3 sample (#202)
anovik Sep 6, 2023
f8f6c3d
Update readme & WinUI3 version prefix
bezysoftware Sep 6, 2023
c0e5d25
Build for WinUI3
bezysoftware Sep 6, 2023
1221cb1
Fix winui3 CI build
bezysoftware Sep 6, 2023
cf8d114
Include Auth.UI dll in WinUI3 package
bezysoftware Sep 7, 2023
72514a2
Include dll in WinUI3 package
bezysoftware Sep 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[*.cs]

# CS1591: Missing XML comment for publicly visible type or member
dotnet_diagnostic.CS1591.severity = silent
19 changes: 19 additions & 0 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 180
# Number of days of inactivity before a stale issue is closed
daysUntilClose: 7
# Issues with these labels will never be considered stale
exemptLabels:
- pinned
- security
- enhancement
- up-for-grabs
# Label to use when marking an issue as stale
staleLabel: stale
# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
# Comment to post when closing a stale issue. Set to `false` to disable
closeComment: Closing the issue due to inactivity. Feel free to re-open
73 changes: 73 additions & 0 deletions .github/workflows/dotnetcore.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: build

on:
push:
branches: '**'
tags: 'v*.*.*'
pull_request:

jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6
- name: Setup MSBuild
uses: microsoft/[email protected]
- name: Build
run: .\build\build-libs.ps1
env:
DOTNET_CLI_TELEMETRY_OPTOUT: 1
- name: Run Tests
env:
FIREBASE_AUTH_TEST_API_KEY: ${{ secrets.FIREBASE_AUTH_TEST_API_KEY }}
FIREBASE_AUTH_TEST_DOMAIN: ${{ secrets.FIREBASE_AUTH_TEST_DOMAIN }}
run: .\build\run-tests.ps1
pack:
runs-on: windows-latest
needs: build
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6
- name: Setup MSBuild
uses: microsoft/[email protected]
- name: Pack preview
if: startsWith(github.ref, 'refs/tags/') == false
run: .\build\run-pack.ps1 -preview
env:
DOTNET_CLI_TELEMETRY_OPTOUT: 1
- name: Pack from tag
if: startsWith(github.ref, 'refs/tags/')
run: .\build\run-pack.ps1
env:
DOTNET_CLI_TELEMETRY_OPTOUT: 1
- uses: actions/upload-artifact@v3
with:
name: artifacts
path: ./artifacts
publish:
runs-on: ubuntu-latest
needs: pack
if: github.event_name == 'push'
steps:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6
- uses: actions/download-artifact@v3
with:
name: artifacts
path: ./artifacts
- name: Publish to Feedz.io
if: startsWith(github.ref, 'refs/tags/') == false
run: dotnet nuget push ./artifacts/**/*.nupkg --source https://f.feedz.io/step-up-labs/firebase/nuget/index.json --api-key ${{secrets.FEEDZ_TOKEN}}
- name: Publish to Nuget.org
if: startsWith(github.ref, 'refs/tags/')
run: dotnet nuget push ./artifacts/**/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{secrets.NUGET_TOKEN}}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

build/temp
samples/UWP/BundleArtifacts

# User-specific files
*.suo
Expand All @@ -17,7 +20,6 @@
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/
Expand Down
317 changes: 317 additions & 0 deletions Firebase.Auth.sln

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion LICENSE → LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 Step Up Labs
Copyright (c) 2019 Step Up Labs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
240 changes: 207 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,226 @@
# FirebaseAuthentication.net
[![AppVeyor Build status](https://ci.appveyor.com/api/projects/status/rwmdgqcb7is2clqp?svg=true)](https://ci.appveyor.com/project/bezysoftware/firebase-authentication-dotnet)
[![build](https://github.com/step-up-labs/firebase-authentication-dotnet/workflows/build/badge.svg)](https://github.com/step-up-labs/firebase-authentication-dotnet/actions)
[![latest version](https://img.shields.io/nuget/v/FirebaseAuthentication.net)](https://www.nuget.org/packages/FirebaseAuthentication.net)
[![feedz.io](https://img.shields.io/badge/endpoint.svg?url=https%3A%2F%2Ff.feedz.io%2Fstep-up-labs%2Ffirebase%2Fshield%2FFirebaseAuthentication.net%2Flatest)](https://f.feedz.io/step-up-labs/firebase/packages/FirebaseAuthentication.net/latest/download)

Firebase authentication library. It can generate Firebase auth token based on given OAuth token (issued by Google, Facebook...). This Firebase token can then be used with REST queries against Firebase Database endpoints. See [FirebaseDatabase.net](https://github.com/step-up-labs/firebase-database-dotnet) for a C# library wrapping the Firebase Database REST queries.
FirebaseAuthentication.net is an unofficial C# implementation of [Firebase Authentication](https://firebase.google.com/docs/auth)
and [FirebaseUI](https://firebase.google.com/docs/auth).

The libraries provide a drop-in auth solution that handles the flows for signing in users with email addresses and passwords, Identity Provider Sign In including Google, Facebook, GitHub, Twitter, Apple, Microsoft and anonymous sign-in.

The solution consists of 5 libraries - a base one and 4 platform specific ones:
* FirebaseAuthentication<strong>.net</strong> targets [.NET Standard 2.0](https://github.com/dotnet/standard/blob/master/docs/versions.md)
* FirebaseAuthentication<strong>.WPF</strong> targets [WPF on .NET 6](https://github.com/dotnet/wpf)
* FirebaseAuthentication<strong>.UWP</strong> targets [UWP with min version 19041](https://docs.microsoft.com/en-us/windows/uwp/updates-and-versions/choose-a-uwp-version)
* FirebaseAuthentication<strong>.WinUI3</strong> targets [WinUI3](https://learn.microsoft.com/en-us/windows/apps/winui/winui3/)
* FirebaseAuthentication<strong>.Maui</strong> targets Maui (*TODO*)

## Installation
```csharp
// Install release version
Install-Package FirebaseAuthentication.net

Either via Visual Studio [Nuget](https://www.nuget.org/packages/FirebaseAuthentication.net) package manager, or from command line:

```powershell
# base package
dotnet add package FirebaseAuthentication.net

# Platform specific FirebaseUI (has dependency on base package)
dotnet add package FirebaseAuthentication.WPF
dotnet add package FirebaseAuthentication.UWP
dotnet add package FirebaseAuthentication.WinUI3
dotnet add package FirebaseAuthentication.Maui
```

## Supported frameworks
* .NET Standard 1.1 - see https://github.com/dotnet/standard/blob/master/docs/versions.md for compatibility matrix
Use the `--version` option to specify a [preview version](https://www.nuget.org/packages/FirebaseAuthentication.net/absoluteLatest) to install.

## Supported scenarios
* Login with Google / Facebook / Github / Twitter OAuth tokens
* Anonymous login
* Login with email + password
* Create new user with email + password
* Send a password reset email
* Link two accounts together
Daily preview builds are also available on [feedz.io](https://feedz.io). Just add the following Package Source to your Visual Studio:

```
https://f.feedz.io/step-up-labs/firebase/nuget/index.json
```

## Usage

In general the terminology and API naming conventions try to follow the official JavaScript implementation, adjusting it to fit the .NET conventions.
E.g. `signInWithCredential` is called `SignInWithCredentialAsync` because it is meant to be `await`ed, but otherwise the terminology should be mostly the same.


### Samples
There are currently 3 sample projects in the [samples folder](/samples/):

* .NET Core Console application (uses only the base library, no UI)
* WPF sample with UI
* UWP sample with UI
* WinUI3 sample with UI

Feel free to clone the repo and check them out, just don't forget to add your custom API keys and other setup (typically in `Program.cs` or `App.xaml.cs`).

![](art/SampleWPF.png)

### Setup

For general Firebase setup, refer to the [official documentation](https://firebase.google.com/docs/auth) which discusses the general concepts and individual providers in detail.
You might also want to check out the first two steps in this [web documentation](https://firebase.google.com/docs/web/setup).
Notice that Firebase doesn't officially support Windows as a platform so you will have to register your application as a web app in [Firebase Console](https://console.firebase.google.com/).

### FirebaseAuthentication.net

The base library gives you the same features as the official *Firebase SDK Authentication*, that is without any UI. Your entrypoint is the `FirebaseAuthClient`.

```csharp
var authProvider = new FirebaseAuthProvider(new FirebaseConfig(FirebaseApiKey));
var facebookAccessToken = "<login with facebook and get oauth access token>";

var auth = await authProvider.SignInWithOAuthAsync(FirebaseAuthType.Facebook, facebookAccessToken);

var firebase = new FirebaseClient("https://dinosaur-facts.firebaseio.com/");
var dinos = await firebase
.Child("dinosaurs")
.WithAuth(auth.FirebaseToken)
.OnceAsync<Dinosaur>();

foreach (var dino in dinos)
// main namespaces
using Firebase.Auth;
using Firebase.Auth.Providers;
using Firebase.Auth.Repository;

// Configure...
var config = new FirebaseAuthConfig
{
Console.WriteLine($"{dino.Key} is {dino.Object.Height}m high.");
}
ApiKey = "<API KEY>",
AuthDomain = "<DOMAIN>.firebaseapp.com",
Providers = new FirebaseAuthProvider[]
{
// Add and configure individual providers
new GoogleProvider().AddScopes("email"),
new EmailProvider()
// ...
},
// WPF:
UserRepository = new FileUserRepository("FirebaseSample") // persist data into %AppData%\FirebaseSample
// UWP:
UserRepository = new StorageRepository() // persist data into ApplicationDataContainer
};

// ...and create your FirebaseAuthClient
var client = new FirebaseAuthClient(config);
```

## Facebook setup
Notice the `UserRepository`. This tells `FirebaseAuthClient` where to store the user's credentials.
By default the libraries use in-memory repository; to preserve user's credentials between application runs, use `FileUserRepository` (or your custom implementation of `IUserRepository`).

Under [Facebook developers page for your app](https://developers.facebook.com/) make sure you have a similar setup:
After you have your `client`, you can sign-in or sign-up the user with any of the configured providers.

![Logo](/art/FacebookSetup.png)
```csharp
// anonymous sign in
var user = await client.SignInAnonymouslyAsync();

// sign up or sign in with email and password
var userCredential = await client.CreateUserWithEmailAndPasswordAsync("email", "pwd", "Display Name");
var userCredential = await client.SignInWithEmailAndPasswordAsync("email", "pwd");

// sign in via provider specific AuthCredential
var credential = TwitterProvider.GetCredential("access_token", "oauth_token_secret");
var userCredential = await client.SignInWithCredentialAsync(credential);

## Google setup
// sign in via web browser redirect - navigate to given uri, monitor a redirect to
// your authdomain.firebaseapp.com/__/auth/handler
// and return the whole redirect uri back to the client;
// this method is actually used by FirebaseUI
var userCredential = await client.SignInWithRedirectAsync(provider, async uri =>
{
return await OpenBrowserAndWaitForRedirectToAuthDomain(uri);
});
```

In the [developer console](https://console.developers.google.com/apis/credentials) make sure you have an OAuth client (set it either as iOS or Android app, that should work).
As you can see the sign-in methods give you a `UserCredential` object, which contains an `AuthCredential` and a `User` objects.
`User` holds details about a user as well as some useful methods, e.g. `GetIdTokenAsync()` to get a valid *IdToken* you can use as an access token to other Firebase API (e.g. Realtime Database).

```csharp
// user and auth properties
var user = userCredential.User;
var uid = user.Uid;
var name = user.Info.DisplayName; // more properties are available in user.Info
var refreshToken = user.Credential.RefreshToken; // more properties are available in user.Credential

// user methods
var token = await user.GetIdTokenAsync();
await user.DeleteAsync();
await user.ChangePasswordAsync("new_password");
await user.LinkWithCredentialAsync(authCredential);
```

To sign out a user simply call
```csharp
client.SignOut();
```

### FirebaseUI

The platform specific UI libraries use the `FirebaseAuthClient` under the hood, but need to be initilized via the static `Initialize` method of `FirebaseUI`:

```csharp
// Initialize FirebaseUI during your application startup (e.g. App.xaml.cs)
FirebaseUI.Initialize(new FirebaseUIConfig
{
ApiKey = "<API KEY>",
AuthDomain = "<DOMAIN>.firebaseapp.com",
Providers = new FirebaseAuthProvider[]
{
new GoogleProvider().AddScopes("email"),
new EmailProvider()
// and others
},
PrivacyPolicyUrl = "<PP URL>",
TermsOfServiceUrl = "<TOS URL>",
IsAnonymousAllowed = true,
UserRepository = new FileUserRepository("FirebaseSample") // persist data into %AppData%\FirebaseSample
});
```

Notice the `UserRepository`. This tells FirebaseUI where to store the user's credentials.
By default the libraries use in-memory repository; to preserve user's credentials between application runs, use `FileUserRepository` (or your custom implementation of `IUserRepository`).

FirebaseUI comes with `FirebaseUIControl` you can use in your xaml as follows:

```xml
<!--WPF Sample-->
<Page x:Class="Firebase.Auth.Wpf.Sample.LoginPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:firebase="clr-namespace:Firebase.Auth.UI;assembly=Firebase.Auth.UI.WPF"
mc:Ignorable="d"
d:DesignHeight="450"
d:DesignWidth="800">

<Grid>
<firebase:FirebaseUIControl>
<firebase:FirebaseUIControl.Header>
<!--Custom content shown above the provider buttons-->
<Image
Height="150"
Source="/Assets/firebase.png"
/>
</firebase:FirebaseUIControl.Header>
</firebase:FirebaseUIControl>
</Grid>
</Page>
```

Toggling the visibility of this UI control is up to you, depending on your business logic.
E.g. you could show it as a popup, or a `Page` inside a `Frame` etc.
You would typically want to toggle the control's visibility in response to the `AuthStateChanged` event:

```csharp
// subscribe to auth state changes
FirebaseUI.Instance.Client.AuthStateChanged += this.AuthStateChanged;

private void AuthStateChanged(object sender, UserEventArgs e)
{
// the callback is not guaranteed to be on UI thread
Application.Current.Dispatcher.Invoke(() =>
{
if (e.User == null)
{
// no user is signed in (first run of the app, user signed out..), show login UI
this.ShowLoginUI();
}
else if (this.loginUIShowing)
{
// user signed in (or was already signed in), hide the login UI
// this event can be raised multiple times (e.g. when access token gets refreshed), you need to be ready for that
this.HideLoginUI();
}
});
}
```
Binary file removed art/FacebookSetup.png
Binary file not shown.
Binary file added art/SampleWPF.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions build/build-libs.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dotnet build --configuration release .\src\Auth\Auth.csproj
dotnet build --configuration release .\src\Auth.UI\Auth.UI.csproj
dotnet build --configuration release .\src\Auth.UI.WPF\Auth.UI.WPF.csproj
dotnet build --configuration release .\src\Auth.UI.WinUI3\Auth.UI.WinUI3.csproj
msbuild /restore /p:Configuration=Release .\src\Auth.UI.UWP\Auth.UI.UWP.csproj
4 changes: 4 additions & 0 deletions build/build-samples.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dotnet build --configuration release .\samples\Console\Auth.Console.Sample.csproj
dotnet build --configuration release .\samples\WPF\Auth.WPF.Sample.csproj
dotnet build --configuration release .\samples\WinUI3\Auth.WinUI3.Sample.csproj
msbuild /restore /p:Configuration=Debug .\samples\UWP\Auth.UWP.Sample.csproj
Loading