benxu.AppPlatform.Firebase.Auth 2.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package benxu.AppPlatform.Firebase.Auth --version 2.0.0
                    
NuGet\Install-Package benxu.AppPlatform.Firebase.Auth -Version 2.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="benxu.AppPlatform.Firebase.Auth" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="benxu.AppPlatform.Firebase.Auth" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="benxu.AppPlatform.Firebase.Auth" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add benxu.AppPlatform.Firebase.Auth --version 2.0.0
                    
#r "nuget: benxu.AppPlatform.Firebase.Auth, 2.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package benxu.AppPlatform.Firebase.Auth@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=benxu.AppPlatform.Firebase.Auth&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=benxu.AppPlatform.Firebase.Auth&version=2.0.0
                    
Install as a Cake Tool

benxu.AppPlatform.Firebase.Auth

Firebase Authentication 實作套件 - 使用官方/社群套件 (Plugin.FirebaseAuth) 提供各平台的原生認證功能。

特色

  • 真實 Firebase 整合:使用 Plugin.FirebaseAuth 進行原生 API 呼叫。
  • Google 登入:支援 Android 平台原生 Google 登入 (GoogleSignInHelper)。
  • Email/Password:完整的註冊、登入、密碼重設流程。
  • 自動 Token 刷新:背景服務自動刷新 Access Token。
  • 狀態同步:自動將認證狀態同步至 IAppStateManager

支援平台

  • Android (支援 Email/Password,Google 登入)
  • iOS (支援 Email/Password,Google 登入尚未實作)

安裝

  1. 安裝套件:

    dotnet add package benxu.AppPlatform.Firebase.Auth
    
  2. 平台設定:

    • Android: 需將 google-services.json 放置於 Platforms/Android 並設定 Build Action 為 GoogleServicesJson
    • iOS: 需將 GoogleService-Info.plist 放置於 Platforms/iOS 並設定 Build Action 為 BundleResource

使用方式

1. 註冊服務

MauiProgram.cs 中:

using benxu.AppPlatform.MAUI.Bootstrap.Extensions;

builder.UseAppPlatform(options =>
{
    options.UseFirebaseAuth(auth =>
    {
        auth.EnableAutoTokenRefresh = true;
        
        // Android Google 登入設定
        auth.GoogleWebClientId = "YOUR_WEB_CLIENT_ID.apps.googleusercontent.com";
        auth.GoogleRedirectUri = "com.googleusercontent.apps.YOUR_CLIENT_ID:/oauth2redirect";
    });
});

2. 使用認證功能

@inject IAuthService AuthService

@code {
    private async Task Login()
    {
        // Google 登入 (Android)
        var result = await AuthService.SignInWithGoogleAsync();
        
        // 或 Email 登入
        // var result = await AuthService.SignInWithEmailAsync("user@example.com", "123456");

        if (result.IsSuccess)
        {
            Console.WriteLine($"使用者: {result.Data.User.Email}");
        }
    }
}

注意事項

  • 模擬模式 (Simulator Mode):目前尚未實作,設定 options.SimulatorMode = true 目前不會啟用模擬服務,請使用真實裝置或模擬器進行測試。
  • Google 登入:目前僅實作 Android 版本,iOS 版本尚待開發。

依賴項目

  • Plugin.FirebaseAuth
  • benxu.AppPlatform.Core

授權

MIT License - Copyright (c) 2025 benxu

Product Compatible and additional computed target framework versions.
.NET net9.0-android35.0 is compatible.  net9.0-ios18.0 is compatible.  net10.0-android was computed.  net10.0-ios was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on benxu.AppPlatform.Firebase.Auth:

Package Downloads
benxu.AppPlatform.MAUI.Bootstrap

Bootstrap package for benxu App Platform. Provides fluent API for one-line service registration and lifecycle management.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.4 81 2/14/2026
3.0.3 80 2/14/2026
3.0.2 103 1/17/2026
3.0.0 94 1/13/2026
2.0.0 95 1/11/2026
1.0.0 99 12/28/2025