Skip to content
This repository was archived by the owner on Dec 6, 2022. It is now read-only.

Commit

Permalink
#21: Generate JWT locally with Mix task
Browse files Browse the repository at this point in the history
  • Loading branch information
th0mas committed Aug 26, 2020
1 parent 6e2f5d1 commit 9ee32aa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/mix/tasks/smart_home/gen_token.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
defmodule Mix.Tasks.SmartHome.GenToken do
use Mix.Task

@shortdoc "Generate a JWT token for use with local API development"
def run(_) do
IO.puts("Generating JWT Token...")
jwt = SmartHomeAuth.gen_auth_token()

IO.puts("\n\n")
IO.puts(jwt)
end
end
14 changes: 14 additions & 0 deletions lib/smart_home_auth.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,18 @@ defmodule SmartHomeAuth do
if it comes from the database, an external API or others.
"""

@doc """
Generate a local-use authentication token for API development.
"""
@spec gen_auth_token :: binary
def gen_auth_token do
AuthPlug.Token.generate_jwt!(
%{
"id" => 1,
"email" => "test@example.com",
"auth_provider" => "local-dev",
"given_name" => "Dev Superuser"
})
end
end

0 comments on commit 9ee32aa

Please sign in to comment.