Current section

4 Versions

Jump to

Compare versions

27 files changed
+1051 additions
-269 deletions
  @@ -1,4 +0,0 @@
1 - # Used by "mix format"
2 - [
3 - inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
4 - ]
  @@ -1,6 +1,8 @@
1 1 # ExFirebase
2 2
3 - A limited implementation of a Firebase Admin SDK in Elixir.
3 + Firebase Admin SDK in Elixir
4 +
5 + [Documentation](https://hexdocs.pm/ex_firebase/ExFirebase.html)
4 6
5 7 ## Installation
6 8
  @@ -8,7 +10,7 @@ Install from Hex
8 10
9 11 ```elixir
10 12 def deps do
11 - [{:ex_firebase, "~> 0.1.0"}]
13 + [{:ex_firebase, "~> 0.2.0"}]
12 14 end
13 15 ```
14 16
  @@ -24,36 +26,35 @@ Run `mix deps.get`
24 26
25 27 ## Configuration
26 28
27 - Add your Firebase Project ID to your `config/config.exs` file:
29 + [Setup Firebase](https://firebase.google.com/docs/admin/setup) and generate a private key for your service account
30 +
31 + Add your Firebase Project ID and service account key path to your `config/config.exs` file:
28 32
29 33 ```elixir
30 34 config :ex_firebase,
31 - project_id: "your-project-id"
35 + project_id: "your-project-id",
36 + service_account_path: "/path/to/your/key.json",
37 + queue_interval: 1000, # frequency in ms queued messages are sent
38 + queue_batch_size: 10 # number of messages sent per queue_interval
32 39 ```
33 40
34 - ## Usage
41 + Instead of specifying a file with `service_account_path`, you can set the following variables:
35 42
36 43 ```elixir
37 - iex> ExFirebase.Auth.verify_token("eyJhbGciOiJS...")
38 - {:ok,
39 - %JOSE.JWT{
40 - fields: %{
41 - "aud" => "your-project-id",
42 - "auth_time" => 1540314428,
43 - "exp" => 1540318028,
44 - "firebase" => %{
45 - "identities" => %{"phone" => ["+16505553434"]},
46 - "sign_in_provider" => "phone"
47 - },
48 - "iat" => 1540314428,
49 - "iss" => "https://securetoken.google.com/your-project-id",
50 - "phone_number" => "+16505553434",
51 - "sub" => "O5dHhHaWzsgUdNo6jIeTrWykPVd2",
52 - "user_id" => "O5dHhHaWzsgUdNo6jIeTrWykPVd2"
53 - }
54 - }}
44 + config :ex_firebase,
45 + private_key: System.get_env("FIREBASE_PRIVATE_KEY"),
46 + client_email: System.get_env("FIREBASE_CLIENT_EMAIL")
55 47 ```
56 48
49 + ## Supported Features
50 +
51 + - [Authentication](https://hexdocs.pm/ex_firebase/ExFirebase.Auth.html)
52 + - [OAuth2 Access Token](https://hexdocs.pm/ex_firebase/ExFirebase.Auth.html#get_access_token/0) - [more](https://developers.google.com/identity/protocols/OAuth2ServiceAccount)
53 + - [Verify ID token](https://hexdocs.pm/ex_firebase/ExFirebase.Auth.html#verify_token/1) - [more](https://firebase.google.com/docs/auth/admin/verify-id-tokens)
54 + - [Messaging](https://hexdocs.pm/ex_firebase/ExFirebase.Messaging.html)
55 + - [FCM Push Notifications](https://hexdocs.pm/ex_firebase/ExFirebase.Messaging.html#send/1) - [more](https://firebase.google.com/docs/cloud-messaging/concept-options)
56 + - [Rate Limited FCM Requests](https://hexdocs.pm/ex_firebase/ExFirebase.Messaging.html#queue/1)
57 +
57 58 ## License
58 59
59 60 MIT. See `LICENSE` file in repository.
  @@ -3,27 +3,45 @@
3 3 {<<"description">>,<<"Lightweight Firebase Admin SDK">>}.
4 4 {<<"elixir">>,<<"~> 1.7">>}.
5 5 {<<"files">>,
6 - [<<"lib">>,<<"lib/ex_firebase">>,<<"lib/ex_firebase.ex">>,
7 - <<"lib/ex_firebase/application.ex">>,<<"lib/ex_firebase/auth.ex">>,
8 - <<"lib/ex_firebase/key_manager.ex">>,<<".formatter.exs">>,<<"mix.exs">>,
6 + [<<"lib/ex_firebase.ex">>,<<"lib/ex_firebase/assertions.ex">>,
7 + <<"lib/ex_firebase/auth/access_token_manager.ex">>,
8 + <<"lib/ex_firebase/auth/api.ex">>,<<"lib/ex_firebase/auth/auth.ex">>,
9 + <<"lib/ex_firebase/auth/certificate.ex">>,<<"lib/ex_firebase/auth/jwt.ex">>,
10 + <<"lib/ex_firebase/auth/public_key_manager.ex">>,
11 + <<"lib/ex_firebase/auth/token_verifier.ex">>,
12 + <<"lib/ex_firebase/config.ex">>,<<"lib/ex_firebase/error.ex">>,
13 + <<"lib/ex_firebase/http_client.ex">>,<<"lib/ex_firebase/http_stub.ex">>,
14 + <<"lib/ex_firebase/messaging/api.ex">>,
15 + <<"lib/ex_firebase/messaging/messaging.ex">>,
16 + <<"lib/ex_firebase/messaging/queue_consumer.ex">>,
17 + <<"lib/ex_firebase/messaging/queue_consumer_supervisor.ex">>,
18 + <<"lib/ex_firebase/messaging/queue_monitor.ex">>,
19 + <<"lib/ex_firebase/messaging/queue_producer.ex">>,
20 + <<"lib/ex_firebase/messaging/queue_producer_consumer.ex">>,<<"mix.exs">>,
9 21 <<"README.md">>,<<"LICENSE">>]}.
10 22 {<<"licenses">>,[<<"MIT">>]}.
11 23 {<<"links">>,[{<<"GitHub">>,<<"https://github.com/loopsocial/ex_firebase">>}]}.
24 + {<<"maintainers">>,[<<"Ben Hansen">>]}.
12 25 {<<"name">>,<<"ex_firebase">>}.
13 26 {<<"requirements">>,
14 27 [[{<<"app">>,<<"jose">>},
15 28 {<<"name">>,<<"jose">>},
16 29 {<<"optional">>,false},
17 - {<<"repository">>,<<"hexpm">>},
18 30 {<<"requirement">>,<<"~> 1.8">>}],
19 31 [{<<"app">>,<<"poison">>},
20 32 {<<"name">>,<<"poison">>},
21 33 {<<"optional">>,false},
22 - {<<"repository">>,<<"hexpm">>},
23 34 {<<"requirement">>,<<"~> 3.1">>}],
24 35 [{<<"app">>,<<"httpoison">>},
25 36 {<<"name">>,<<"httpoison">>},
26 37 {<<"optional">>,false},
27 - {<<"repository">>,<<"hexpm">>},
28 - {<<"requirement">>,<<"~> 1.4">>}]]}.
29 - {<<"version">>,<<"0.1.0">>}.
38 + {<<"requirement">>,<<"~> 1.4">>}],
39 + [{<<"app">>,<<"gen_stage">>},
40 + {<<"name">>,<<"gen_stage">>},
41 + {<<"optional">>,false},
42 + {<<"requirement">>,<<"~> 0.14.1">>}],
43 + [{<<"app">>,<<"gproc">>},
44 + {<<"name">>,<<"gproc">>},
45 + {<<"optional">>,false},
46 + {<<"requirement">>,<<"~> 0.5.0">>}]]}.
47 + {<<"version">>,<<"0.2.0">>}.
  @@ -1,5 +1,22 @@
1 1 defmodule ExFirebase do
2 2 @moduledoc """
3 - A limited Firebase Admin SDK implementation
3 + Firebase Admin SDK
4 4 """
5 +
6 + use Application
7 +
8 + @doc false
9 + def start(_type, _args) do
10 + children = [
11 + ExFirebase.Auth.AccessTokenManager,
12 + ExFirebase.Auth.PublicKeyManager,
13 + ExFirebase.Messaging.QueueProducer,
14 + ExFirebase.Messaging.QueueProducerConsumer,
15 + ExFirebase.Messaging.QueueConsumerSupervisor,
16 + ExFirebase.Messaging.QueueMonitor
17 + ]
18 +
19 + opts = [strategy: :one_for_one, name: ExFirebase.Supervisor]
20 + Supervisor.start_link(children, opts)
21 + end
5 22 end
  @@ -1,12 +0,0 @@
1 - defmodule ExFirebase.Application do
2 - use Application
3 -
4 - def start(_type, _args) do
5 - children = [
6 - ExFirebase.KeyManager
7 - ]
8 -
9 - opts = [strategy: :one_for_one, name: ExFirebase.Supervisor]
10 - Supervisor.start_link(children, opts)
11 - end
12 - end
Loading more files…