chaingng / oauth-api-server

API server with oauth2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

oauth-api-server

Provide Simple API server with oauth2.0

Setup

Install

bundle
bundle exec rake db:migrate

Launch

bundle exec rails server -p 5000

Authentication & API Request Flow

Register your Application

access oauth/applications

newapp

then register new application

register

Authorization

click Authorize button

authorizebutton

or Authorize API request

curl -X GET http://localhost:5000/oauth/authorize \
-F response_type=code \
-F client_id=d6da6ee768631ade98798d9fcc632621acb20e418c46c5bbd7d36f22c4874371 \
-F redirect_uri=http://www.yahoo.co.jp/ \
-F scope=info

Redirect User to Login Page

After Authorize action, redirect to user login page

redirect

Require authorization

After login or signup, move to require authorization page confirmauthorize

If clck Authorize, redirect specified redirect_url with authorization code

Token Request

curl -X POST http://localhost:5000/oauth/token \
-F grant_type=authorization_code \
-F client_id=d6da6ee768631ade98798d9fcc632621acb20e418c46c5bbd7d36f22c4874371 \
-F client_secret=c1c89bcd048923bac21820f7e3653de756b5ba58e94875be2d12db97adfd4274 \
-F code=92c8ab063daec8593a8b6191f4f6b07d0313e9e93ecd1e76b4a160b5069e962b \
-F redirect_uri=http://www.yahoo.co.jp/ \
-F scope=info

then, response like this

{"access_token":"2d1a69418f627ef397285c8a7bf2877e66c4febf709e09fbc958ec3b08b1430e","token_type":"bearer","expires_in":7200,"scope":"info","created_at":1483685928}

API Request

curl -X GET http://localhost:5000/api/user \
-H "Authorization: Bearer 142107ad12a550595faca319491921d7b358df4e9edddd87ee46a193c7c09f97"

then, response like this

{"id":1,"email":"test@example.com","created_at":"2017-01-06T06:28:46.713Z","updated_at":"2017-01-06T07:11:35.212Z"}

About

API server with oauth2


Languages

Language:Ruby 86.3%Language:HTML 9.9%Language:CSS 1.8%Language:JavaScript 1.2%Language:CoffeeScript 0.7%