1
0
mirror of https://github.com/mgerb/classic-wow-forums synced 2026-01-11 01:22:49 +00:00

authentication with persistence working

This commit is contained in:
2018-01-01 18:55:00 -06:00
parent e856cc5172
commit 135ce3a5d6
14 changed files with 172 additions and 38 deletions

View File

@@ -1,16 +1,21 @@
defmodule MyAppWeb.BattleNetController do
use MyAppWeb, :controller
alias MyAppWeb.Response
alias MyApp.BattleNet.Auth
alias MyApp.BattleNet
alias MyApp.Data
alias MyApp.JWT
# https://us.battle.net/oauth/authorize?redirect_uri=https://localhost/api/battlenet/authorize&scope=wow.profile&client_id=vxqv32fddxsy6cmk6259amtymbuzmfrq&response_type=code
@spec authorize(map, map) :: any
def authorize(conn, %{"code" => code}) when not is_nil(code) do
{output, status} = case Auth.get_token(code) do
{:ok, token} -> {token, 200}
{:error, err} -> {err, 400}
end
{output, status} = code
|> BattleNet.Auth.get_access_token
|> BattleNet.User.get_user
|> Data.User.upsert_user
|> JWT.add_jwt
|> Response.put_resp
conn
|>put_status(status)