GithubHelp home page GithubHelp logo

dwyl / auth-mvp Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 0.0 1.34 MB

:key: Prototype Authentication Service

Home Page: https://auth-mvp.herokuapp.com/

Elixir 74.87% CSS 16.19% JavaScript 5.68% HTML 3.24% Procfile 0.03%

auth-mvp's People

Contributors

dependabot[bot] avatar nelsonic avatar simonlab avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

auth-mvp's Issues

Create /person/info endpoint

Now that the auth service returns a jwt on authenticate, we want to be able to fetch the information about a person based on this jwt.

  • Create the /person/info endpoint where the header of the request will contain the jwt.

Use Latest Auth Package TestDouble (Remove Duplicate Mocks)

We recently added a TestDouble to both elixir-auth-github and elixir-auth-google which makes it much easier for people using those packages to test their code. ๐ŸŽ‰ see: dwyl/elixir-auth-google#35

That means we no longer need to have the files:

Additionally we will no longer need the following configuration lines in test.exs:

auth-mvp/config/test.exs

Lines 19 to 20 in f027488

config :auth_mvp, :elixir_auth_google, AuthMvp.Mock.ElixirAuthGoogle
config :auth_mvp, :elixir_auth_github, AuthMvp.Mock.ElixirAuthGithub

Todo

  • Update packages in mix.exs
  • Remove config lines from test.exs
  • Update Tests if Necessary

Create html auth page

To allow applications to use the dwyl authentication service directly without using the api, we need to create a specific controller which will display the oauth urls to login with Google or Github.

see also: dwyl/app-mvp-elm#32
image

Initialise Phoenix application

linked to dwyl/auth#40 (comment)

  • Create a new Phoenix application with mix phx.new auth-mvp --app auth_mvp . We might need to render some html from the auth application so I'm not adding the --no-webpack and --no-html option

  • Use elixir-auth-google and elixir-auth-github

    • Add the packages as dependencies
    • Create /auth/urls endpoint using the api scope and returns the list of the oauth urls
    • Create callback endpoints. These endpoints are were the Google and Github application will send the token once the user authenticate. /auth/google/callback and `/auth/github/callback
  • Allow Cross Origin Resource Sharing to allow requests to access the auth api endpoints

    • Add the cors_plug dependency
    • Update the endpoint.ex file to add the line plug CORSPlug, origin: ["*"]
  • Deploy the application on Heroku

    • Define the callback url to match the heroku name of the application. This allow the /api/auth/github/callback (and the google one) to be available for the Oauth apps
    • Generate a new secret key and add it to the environment variables on Heroku, mix phx.gen.secret
    • Add Postgres resource on Heroku
    • Follow the heroku deployment guide to make sure the application is ready: https://hexdocs.pm/phoenix/heroku.html

Compilation error in file lib/plugs/authenticate_person.ex

After running git pull on master branch and mix deps.get,
I attempted to run mix test on localhost and got the following error:

Compiling 3 files (.ex)

== Compilation error in file lib/plugs/authenticate_person.ex ==
** (ArgumentError) ranges (first..last) expect both sides to be integers, got: TokenAuthMvp..verify_and_validate(jwt)
    (elixir 1.10.1) lib/kernel.ex:3287: Kernel.range/3
    (elixir 1.10.1) expanding macro: Kernel.".."/2
    lib/plugs/authenticate_person.ex:33: AuthMvp.Plugs.AuthenticatePerson.validate_token/2

The line in question authenticate_person.ex:33 is AuthMvp.Token.verify_and_validate(jwt):

defp validate_token(conn, jwt) do
case AuthMvp.Token.verify_and_validate(jwt) do
{:ok, values} ->
# convert map of string to atom, see https://stackoverflow.com/questions/31990134/how-to-convert-map-keys-from-strings-to-atoms-in-elixir
claims = for {key, val} <- values, into: %{}, do: {String.to_atom(key), val}
assign(conn, :claims, claims)
{:error, _} -> unauthorized(conn)
end
end

I have all the required environment variables listed in .env_sample ...

@SimonLab can you help clarify how to run the project on localhost?

Save profile image

Google and Github Oauth2 allow us to get basic information about the user.
We are currently only saving in our Postgres person database the email of the user:

schema "people" do
field :email, :string
field :verified, :boolean, default: false
has_many :sessions, AuthMvp.People.Session
timestamps()
end

We want now to be able to save the profile image of the user.
With Google the image url is already returned via ElixirAuthGoogle package under the picture value:

{:ok, profile} = ElixirAuthGoogle.get_user_profile(token.access_token)

With Github the value to get will be saved under avatar_url

  • Update the schema to add an avatar string field
  • Add a new migration to create the avatar field in the database
  • Update the person changeset to cast the avatar value:
def changeset(person, attrs) do
    person
    |> cast(attrs, [:email, :verified])
    |> validate_required([:email, :verified])
  end

Create people and session tables

On authentication we want know to be able to create person and session data.

  • Create person table containing email and verified fields
  • Create session table with valid field

using context: mix phx.gen.context People Person people email:string verified:boolean

This basic structure should be enough to allow a person to login and create a new session for the applications using auth-mvp. We will update the list of fields on the next PRs

see also:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.