https://github.com/r8/ash_authentication_firebase
Firebase token authentication strategy for AshAuthentication.
https://github.com/r8/ash_authentication_firebase
ash authentication elixir firebase firebase-auth
Last synced: 7 months ago
JSON representation
Firebase token authentication strategy for AshAuthentication.
- Host: GitHub
- URL: https://github.com/r8/ash_authentication_firebase
- Owner: r8
- License: mit
- Created: 2023-11-07T21:22:12.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-11-25T10:29:08.000Z (10 months ago)
- Last Synced: 2025-02-15T19:54:42.327Z (8 months ago)
- Topics: ash, authentication, elixir, firebase, firebase-auth
- Language: Elixir
- Homepage:
- Size: 27.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# AshAuthentication.Firebase
[](https://hex.pm/packages/ash_authentication_firebase)
[](https://hex.pm/packages/ash_authentication_firebase)Firebase token authentication strategy for [AshAuthentication](https://github.com/team-alembic/ash_authentication).
> 🛠In development. Use at your own risk.
## Installation
The package can be installed by adding `ash_authentication_firebase` to your list of dependencies in mix.exs:
```elixir
def deps do
[
{:ash_authentication_firebase, "~> 0.2.0"}
]
end
```## Usage
Please consult with official [Ash documentation](https://ash-hq.org/docs/guides/ash_authentication/latest/tutorials/getting-started-with-authentication) on how to create your resource.
Add `AshAuthentication.Strategy.Firebase` to your resource `extensions` list and `:firebase` strategy to the `authentication` section:
```elixir
defmodule MyApp.Accounts.User do
use Ash.Resource,
extensions: [AshAuthentication, AshAuthentication.Strategy.Firebase]...
authentication do
api MyApp.Accountsstrategies do
# You can have multiple firebase strategies
firebase :firebase do
project_id "project-123abc"
token_input :firebase_token
end
end
end
...end
```## Secrets and Runtime Configuration
To avoid hardcoding your Firebase project id in your source code, you can use the `AshAuthentication.Secret` behaviour. This allows you to provide the project id through runtime configuration using either an anonymous function or a module.
### Examples:
Using an anonymous function:
```elixir
authentication do
strategies do
firebase :firebase do
project_id fn _path, _resource ->
Application.fetch_env(:my_app, :firebase_project_id)
end
token_input :firebase_token
end
end
end
```Using a module:
```elixir
defmodule MyApp.Secrets do
use AshAuthentication.Secretdef secret_for([:authentication, :strategies, :firebase, :project_id], MyApp.Accounts.User, _opts) do
Application.fetch_env(:my_app, :firebase_project_id)
end
end# And in your resource:
authentication do
strategies do
firebase :firebase do
project_id MyApp.Secrets
token_input :firebase_token
end
end
end
```## Acknowledgements
Inspired by [ExFirebaseAuth](https://github.com/Nickforall/ExFirebaseAuth).