Code Monkey home page Code Monkey logo

oauth2's Introduction

OAuth2

OAuth2 Library for Elixir

Usage

So far, I only have one situation coded out: utilizing an access code with Google's OAuth2 (https://developers.google.com/accounts/docs/OAuth2)

Registration

Start by registering an oauth strategy:

Simple example:

  • This is the same as the multiple strategies example below, it simply sets its name to :default*
params = %{
  client_id: "someid12345",
  client_secret: "somesecret12345",
  redirect_uri: "http://whatever.com/oauth",
  token_endpoint: "https://www.googleapis.com/oauth2/v3/token"
}
OAuth2.register(params)
# > :ok

Multiple strategies:

params1 = %{
  client_id: "someid12345",
  client_secret: "somesecret12345",
  redirect_uri: "http://whatever.com/oauth",
  token_endpoint: "https://www.googleapis.com/oauth2/v3/token"
}
params2 = %{
  client_id: "someid12345",
  client_secret: "somesecret12345",
  redirect_uri: "http://whatever.com/oauth",
  token_endpoint: "https://someotherservice.com/oauth"
}
OAuth2.register(:google, params1)
# > :ok
OAuth2.register(:other, params2)
# > :ok

Utilizing a discovery service:

params = %{
  client_id: "someid12345",
  client_secret: "somesecret12345",
  redirect_uri: "http://whatever.com/oauth"
}
discovery_uri = "https://accounts.google.com/.well-known/openid-configuration"

OAuth2.register(:google, params, discovery_uri)
# > :ok

Authorizing Users

OAuth2.authorize_user("access_code_asdfasdfasdfasdfasdf")
# >  {:ok,
# >   %OAuth2.Response{
# >    body: %{access_token: "asdfasdfasdfasdfsadfasdfasdf",
# >      expires_in: 3600,
# >      id_token: "asdfsadfsadfsadfsadfsadfsadfsadfsadfsadfasdfasdfa",
# >      token_type: "Bearer"},
# >    headers: [{"Cache-Control", "no-cache, no-store, max-age=0, must-revalidate"},
# >     {"Pragma", "no-cache"}, {"Expires", "Fri, 01 Jan 1990 00:00:00 GMT"},
# >     {"Date", "Mon, 05 Jan 2015 22:49:06 GMT"}, {"Vary", "Origin"},
# >     {"Vary", "X-Origin"}, {"Content-Type", "application/json; charset=UTF-8"},
# >     {"X-Content-Type-Options", "nosniff"}, {"X-Frame-Options", "SAMEORIGIN"},
# >     {"X-XSS-Protection", "1; mode=block"}, {"Server", "GSE"},
# >     {"Alternate-Protocol", "443:quic,p=0.02"}, {"Transfer-Encoding", "chunked"}],
# >    status_code: 200
# >    }
# >  }

or

OAuth2.authorize_user(:strategy_name, "codecodecode")

oauth2's People

Contributors

scrogson avatar mgamini avatar nessamurmur avatar

Watchers

James Cloos avatar

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.