• Stars
    star
    71
  • Rank 442,922 (Top 9 %)
  • Language
    Erlang
  • License
    MIT License
  • Created about 12 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Erlang OAuth2 Client

Oauth2 Client

This library is designed to simplify consuming Oauth2 enabled REST Services. It wraps a restclient and takes care of reauthenticating expired access_tokens when needed.

Flows

Implemented flows are:

  • Client Credentials Grant
  • Resource Owner Password Credentials Grant

Example

Retrieve a client with access_token using Password Credentials Grant

1> oauth2c:retrieve_access_token(<<"password">>, <<"Url">>, <<"Uid">>, <<"Pwd">>).
{ok, Headers, Client}

Retrieve a client with access_token using Client Credentials Grant

2> oauth2c:retrieve_access_token(<<"client_credentials">>, <<"Url">>, <<"Client">>, <<"Secret">>).
{ok, Headers, Client}

Microsoft Azure AD: Since parameters are different please use <<"azure_client_credentials">> as Type when retrieving an access token for that service. Be sure to set a Scope if you want to access any of the connected APIs.

2> oauth2c:retrieve_access_token(
    <<"azure_client_credentials">>,
    <<"some_tenant_specific_oauth_token_endpoint">>,
    <<"some_registered_app_id">>,
    <<"some_created_key">>,
    <<"https://graph.microsoft.com">>).
{ok, Headers, Client}

The Opaque Client object is to be used on subsequent requests like:

3> oauth2c:request(get, json, <<"Url">>, [200], Client).
{{ok, Status, Headers, Body} Client2}

See restclient for more info on how requests work.

Twitter Example

-module(oauth2c_twitter_example).

-export([ run/0
        ]).

-define(CONSUMER_SECRET, <<"my_consumer_secret">>).
-define(CONSUMER_KEY, <<"my_consumer_key">>).

-define(OAUTH2_TOKEN_URL, <<"https://api.twitter.com/oauth2/token">>).

-define(USER_TIMELINE_URL(User, StrCount),
        <<"https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name="
          , User, "&count=", StrCount>>).

-define(APP_LIMITS_URL(Resources),
        << "https://api.twitter.com/1.1/application/rate_limit_status.json?resources="
           , Resources>>).
run() ->
    application:ensure_all_started(oauth2c),
    application:ensure_all_started(ssl),
    {ok, _Headers, Client} =
        oauth2c:retrieve_access_token(
          <<"client_credentials">>, ?OAUTH2_TOKEN_URL, ?CONSUMER_KEY,
          ?CONSUMER_SECRET),
    {{ok, _Status1, _Headers1, Tweets}, Client2} =
        oauth2c:request(
          get, json, ?USER_TIMELINE_URL("twitterapi", "4"), [200], Client),
    io:format("Tweets: ~p~n", [Tweets]),
    {{ok, _Status2, _Headers2, Limits}, _Client3} =
        oauth2c:request(
          get, json, ?APP_LIMITS_URL("help,users,search,statuses"),
          [200], Client2),
    io:format("Limits: ~p~n", [Limits]),
    ok.

License

The KIVRA oauth2 library uses an MIT license. So go ahead and do what you want!

More Repositories

1

oauth2

Erlang Oauth2 implementation
Erlang
217
star
2

restclient

Erlang Rest Client
Erlang
88
star
3

giallo

Small and flexible web framework on top of Cowboy
Erlang
67
star
4

email

The Erlang Mail application or Email for short
Erlang
33
star
5

zerolog

Log transport that just works with zero effort.
JavaScript
31
star
6

oauth2_example

Example application for oauth2
Erlang
30
star
7

emagick

Wrapper for Graphics/ImageMagick command line tool.
Erlang
27
star
8

lager_loggly

Loggly backend for lager
Erlang
16
star
9

robotnik

Dr Robotnik web scraper robot factory
Erlang
15
star
10

jsonformat

A Erlang Logger Json Formatter - Structured Logging of Maps to JSON
Erlang
13
star
11

merlin

Erlang
12
star
12

giallo_session

Session Management for Giallo Web Framework
Erlang
10
star
13

money_laundry

πŸ’Έ Erlang Currency and money laundering functions
Erlang
9
star
14

id_token

Erlang application to easily handle ID tokens
Erlang
9
star
15

mechanus_fsm

Mechanus FSM
Erlang
9
star
16

sftp_utils

Erlang SFTP Utils
Erlang
9
star
17

greph

Erlang port of Prismatic's graph package.
Erlang
8
star
18

developer.kivra.com

API Documentation, etc
HTML
7
star
19

fluentd-erlang

Fluentd Erlang Client
Erlang
6
star
20

ehtmltopdf

Erlang wrapper for converting HTML to PDF
Erlang
6
star
21

raven-erlang

Erlang
5
star
22

ews

Erlang Web Services
Erlang
4
star
23

krakend-correlationid

KrakenD middleware for adding Correlation IDs to incoming requests
Go
3
star
24

kivra-api-errors

Kivra API Errors
Erlang
3
star
25

krakend-urlrewrite

KrakenD middleware to rewrite URLs
Go
3
star
26

giallo_examples

Giallo example applications
Erlang
3
star
27

lager_backends

Custom backends for lager
Erlang
2
star
28

angular-popup-service

Library for handling popup boxes in angular
CSS
2
star
29

krakend-sizelimit

KrakenD middleware to limit the size of incoming requests
Go
2
star
30

opentracing-erlang

Opentracing API in Erlang
Erlang
1
star
31

krakend-metalog

KrakenD log formatter and logger middleware
Go
1
star
32

fingerprint_key_store_sample

Kotlin
1
star
33

krakend-shadowproxy

KrakenD middleware for mirroring of proxy (no-op) requests
Go
1
star
34

context

Erlang Standard Context
Erlang
1
star