Grapeã¨Doorkeeperã§Railsã¢ããªã«èªè¨¼ä»ãã®REST-like Web APIãå®è£ ãã å¾ç·¨
Railsãã¥ã¼ããªã¢ã«ã®ç¬¬2çãåèã«ãã¦ä½ã£ããã¤ã¯ãããã°ã«ãGrapeã¨Doorkeeperã使ç¨ãã¦ãOAuthèªå¯ãå©ç¨ããWeb APIãå®è£ ãããã¨è©¦ã¿ã¾ããã
å¾ç·¨ã§ã¯ãåç·¨ã§å®è£ ããAPIã«ãDoorkeeperã使ã£ãOAuthèªå¯ã®æ©è½ãå®è£ ãã¾ãã
å®éã®æãã¦ã¼ã¶èªè¨¼ã¨ãOAuthèªå¯ã¨ããç解ãã¦ããã¨ã¯è¨ãé£ãã®ã§ãã»ãã¥ãªãã£ãä¿ã¤ããã®å¿ è¦ãªæªç½®ãä¸å ¨ã¨ã¯è¨ãã¾ããããã¨ãããããããã£ã½ãåããã®ã¯ã§ãã¾ããã
ç®æ¬¡
- ç®æ¬¡
- è£è¶³ï¼å®è£ ãããAPI v1ã®ä»æ§
- Doorkeeperã®æºå
- Doorkeeperã¨Grapeã®è¨å®
- Doorkeeperããã¢ã¯ã»ã¹ãã¼ã¯ã³ãåå¾
- èªè¨¼ä»ãAPI v1ã®åä½ç¢ºèª
- è足ï¼Strong Parametersã使ã£ã¦Mass Assignmentèå¼±æ§å¯¾çã試ã¿ã
- åèè¨äº
- éçºç°å¢
è£è¶³ï¼å®è£ ãããAPI v1ã®ä»æ§
- ãã¤ã¯ãããã°ã«ãã£ããããããããã¤ã¯ããã¹ããPOSTããã
- APIãå©ç¨ããã¢ããªã®ä½æãèªå¯ã¯ãµã¤ã³ã¤ã³ãã¦ããã¦ã¼ã¶ã®ã¿å¯è½ã«ããã
- ã¤ã¾ãã¨ããTwitter APIã®æ©è½ã縮å°ãããããªAPIãä½ããã
APIã®å®è£
ã試ã¿ããã¤ã¯ãããã°ã¯ãRailsãã¥ã¼ããªã¢ã«ã®ç¬¬2çãåèã«ãã¦ä½ã£ã¦ã¾ãã®ã§ãUser
ã¢ãã«ã¨Micropost
ã¢ãã«ãé¢é£ãã¦æãç«ã£ã¦ãã¾ãã
èªè¨¼ã·ã¹ãã ããèªè¨¼ã·ã¹ãã ãæä¾ããgem
ã使ç¨ããã«Railsã®session
ã¡ã½ããã使ç¨ãã¦æ§ç¯ãã¦ãã¾ãã®ã§ãsession
ã¡ã½ããã使ç¨ããèªè¨¼ã¡ã½ãããSessionsHelperã«å®ç¾©ãã¦ãè²ã
ãªå ´æã§èªè¨¼ã¡ã½ããã使ããããã«ãªã£ã¦ãã¾ãã
Doorkeeperã®æºå
Doorkeeperã®gemã¯ãåç·¨ã§Gemfile
ã«è¿½å ãã¦bundle install
ã¾ã§ãã¦ããã¾ãã
gem 'grape', '0.16.2' gem 'doorkeeper', '4.0.0'
doorkeeper:installã§ã¤ã³ã¹ãã¼ã«
doorkeeper:install
ã§config/initializers/doorkeeper.rb
ãä½ãããã«ã¼ãã£ã³ã°ã«use_doorkeeper
ã追å ããã¾ãã
$rails generate doorkeeper:install Running via Spring preloader in process 14348 create config/initializers/doorkeeper.rb create config/locales/doorkeeper.en.yml route use_doorkeeper =============================================================================== There is a setup that you need to do before you can use doorkeeper. Step 1. Go to config/initializers/doorkeeper.rb and configure resource_owner_authenticator block. Step 2. Choose the ORM: If you want to use ActiveRecord run: rails generate doorkeeper:migration And run rake db:migrate Step 3. That's it, that's all. Enjoy! ===============================================================================
doorkeeper:migrationããã®db:migrate
Doorkeeperã¯OAuthèªå¯ã§ãã¼ã¿ãã¼ã¹ã使ããããrails generate doorkeeper:migration
ã§ãã¤ã°ã¬ã¼ã·ã§ã³ãã¡ã¤ã«ãçæãã¾ãã
$rails generate doorkeeper:migration create db/migrate/20160*********_create_doorkeeper_tables.rb
rake db:migrate
ã§ãã¤ã°ã¬ã¼ã·ã§ã³ãã¡ã¤ã«ã®å
容ããã¼ã¿ãã¼ã¹ã«åæ ãããOAuthèªå¯ã§ä½¿ç¨ãããã¼ãã«ããã¼ã¿ãã¼ã¹ã«ä½æãã¾ãã
$rake db:migrate == 20160********* CreateDoorkeeperTables: migrating =========================== ã» ã» ã» == 20160********* CreateDoorkeeperTables: migrated (0.5095s) ==================
ã©ããªãã¼ãã«ãä½ãããã®ããã¡ããã¨ãã¼ã¿ãã¼ã¹ã確èªãã¦ã¿ã¾ãã
$psql railsapp_development psql (9.5.1) Type "help" for help. railsapp_development=# \d List of relations Schema | Name | Type | Owner --------+----------------------------+----------+---------- public | users | table | railsapp ã» ã» ã» public | oauth_access_grants | table | railsapp public | oauth_access_grants_id_seq | sequence | railsapp public | oauth_access_tokens | table | railsapp public | oauth_access_tokens_id_seq | sequence | railsapp public | oauth_applications | table | railsapp public | oauth_applications_id_seq | sequence | railsapp public | schema_migrations | table | railsapp (11 rows) railsapp_development=#
OAuthèªå¯ã§ä½¿ããããªãã¼ãã«ãã3ã¤ä½æããã¦ã¾ããã
Doorkeeperã¨Grapeã®è¨å®
Doorkeeper::Grape::Helpersã§ãGrapeã使ã£ã¦å®è£ ããAPIã®ã¡ã½ããã¸ã¢ã¯ã»ã¹ããéã«ãDoorkeeperã®èªå¯ãå¿ è¦ã¨ãªãããã«è¨å®ãã¾ãã
config/initializers/doorkeeper.rbã«åæè¨å®ãè¨è¿°ãã
config/initializers/doorkeeper.rb
ã§ãDoorkeeperãèªå¯ã§ãã権éã®ãªã½ã¼ã¹ãªã¼ãã¼*1ãæå®ãã¾ãã
ãªã½ã¼ã¹ãªã¼ãã¼ã¯ããã¤ã¯ãããã°ã®ã¦ã¼ã¶ã«éå®ãããã¨èãã¦ãã¾ãã®ã§ãèªè¨¼ã¡ã½ããã®current_user
*2ã§ãµã¤ã³ã¤ã³ã®ç¶æ
ã確èªãã¦ããµã¤ã³ã¤ã³ãã¦ããªããã°ãµã¤ã³ã¤ã³ãã¼ã¸ã¸ãªãã¤ã¬ã¯ããã¾ãã
Scopes
ã¨ããã§èªå¯ã§ãã権éã®å¶éãã§ãããããªã®ã§ã念ã®ãããã³ã¡ã³ãã¢ã¦ããå¤ãã¦è¨å®ãã¦ããã¾ãã
resource_owner_authenticator do # fail "Please configure doorkeeper resource_owner_authenticator block located in #{__FILE__}" # Put your resource owner authentication logic here. # Example implementation: # User.find_by_id(session[:user_id]) || redirect_to(new_user_session_url) current_user || redirect_to(signin_path) end ã» ã» ã» default_scopes :public optional_scopes :write, :update
APIã®ã¢ã¸ã¥ã¼ã«ã«Doorkeeperã®ãã«ãã¼ã追å ãã
app/api/v1/v1_api.rb
ã«Doorkeeper::Grape::Helpers
ã追å ãã¦ãAPI v1
ã®ã¡ã½ããã«ã¢ã¯ã»ã¹ããéã«ã¯doorkeeper_authorize!
ã§ç¢ºèªããããã«ãã¾ãã
ãã¤ã¯ããã¹ãã®POST
ã«å¿
è¦ãªuser_id
ã«ã¯ãdoorkeeper_token[:resource_owner_id]
ãããªã½ã¼ã¹ãªã¼ãã¼ã®id
ãåå¾ãã¦åã渡ãã¾ãã®ã§ãparams
ãããã¯ããuser_id
ã®è¨è¿°ãåé¤ãã¦ããã¾ãã
require 'doorkeeper/grape/helpers' module V1 class V1API < Grape::API helpers Doorkeeper::Grape::Helpers before do doorkeeper_authorize! end resource :statuses do ã» ã» ã» resource :statuses do ã» ã» ã» desc 'Post new micropost' params do requires :content, type: String end post do Micropost.create!({ user_id: doorkeeper_token[:resource_owner_id], content: params[:content] }) status 201 end end end end
Doorkeeperã®ã«ã¼ãã£ã³ã°ãè¨å®ãã
doorkeeper:install
ã§config/routes.rb
ã«è¿½å ãããuse_doorkeeper
ã®è¨è¿°ãããã°ãDoorkeeperã«èªå¯ãããã¢ããªã±ã¼ã·ã§ã³ã®ä½æãã¢ã¯ã»ã¹ãã¼ã¯ã³ã®çºè¡ã¯ã§ããããã§ãããã¢ããªã±ã¼ã·ã§ã³ã®ä½æãèªå¯ã®éã«ã¯ãSessionsHelperã«å®ç¾©ãã¦ããèªè¨¼ã¡ã½ããã使ç¨ããã¦ã¼ã¶ã®ãµã¤ã³ã¤ã³ã®ç¶æ
ã確èªãããã¨èãã¦ããã®ã§ãuse_doorkeeper
ããããã¯ã«ãã¦ãDoorkeeperã®AuthorizationsController
ã¨ApplicationsController
ãããããç¶æ¿ãããã«ã¹ã¿ã ã³ã³ããã¼ã©ã使ç¨ã§ããããã«ãã¾ãã
Rails.application.routes.draw do use_doorkeeper do controllers authorizations: 'custom_authorizations' controllers applications: 'custom_applications' end mount API::Base => '/' ã» ã» ã»
controller/custom_authorization_controller.rbãä½æãã
èªè¨¼ã¡ã½ããã®current_user
ããconfig/initializers/doorkeeper.rb
ã§ä½¿ããããã«ãããããAuthorizationsController
ãç¶æ¿ããCustomAuthorizationsController
ãä½æããèªè¨¼ã¡ã½ãããå®ç¾©ãã¦ããSessionsHelperãã¤ã³ã¯ã«ã¼ããã¾ãã
class CustomAuthorizationsController < Doorkeeper::AuthorizationsController include SessionsHelper end
controller/custom_applicatinos_controller.rbãä½æãã
Doorkeeperã«èªå¯ãããã¢ããªã±ã¼ã·ã§ã³ã®URIã§ãã/oauth/applications
ã¸ã®ã¢ã¯ã»ã¹ããèªè¨¼ã¡ã½ããã®sined_in_user
ã使ç¨ãã¦ã¦ã¼ã¶ã®ãµã¤ã³ã¤ã³ãå¿
è¦ã¨ãªãããã«ãããã®ã§ãDoorkeeperã®ApplicationsController
ãç¶æ¿ããCustomApplicationsController
ãä½æããèªè¨¼ã¡ã½ãããå®ç¾©ãã¦ããSessionHelperãã¤ã³ã¯ã«ã¼ããã¾ãã
class CustomApplicationsController < Doorkeeper::ApplicationsController include SessionsHelper before_action :signed_in_user end
Doorkeeperããã¢ã¯ã»ã¹ãã¼ã¯ã³ãåå¾
Doorkeeperã®OAuthèªå¯ã®åä½ç¢ºèªãããããã«ãrails server
ãèµ·åããã¢ã¯ã»ã¹ãã¼ã¯ã³ã®åå¾ã試ã¿ã¾ãã
$rails server => Booting WEBrick => Rails 4.2.6 application starting in development on http://localhost:3000 => Run `rails server -h` for more startup options => Ctrl-C to shutdown server [2016-06-18 21:57:52] INFO WEBrick 1.3.1 [2016-06-18 21:57:52] INFO ruby 2.3.0 (2015-12-25) [x86_64-darwin15] [2016-06-18 21:57:52] INFO WEBrick::HTTPServer#start: pid=62210 port=3000
Doorkeeperã«èªå¯ãããã¢ããªã±ã¼ã·ã§ã³ãä½æãã
ãã¤ã¯ãããã°ã«ãµã¤ã³ã¤ã³ãã¦http://localhost:3000/oauth/applications
ã«ã¢ã¯ã»ã¹ããNew Application
ããä½æãã¾ãã
Authorization code
ã®éä»å
ã«ãªãRedirect URI
ãç¨æãã¦ããªãã£ãã®ã§ãDoorkeeperã«ç¨æããã¦ãããã¹ãç¨ã®ãã¥ã¼ã®URIã使ç¨ãã¾ãã
é ç® | ç»é²å 容 | |
---|---|---|
Name | b0npubot | é©å½ã«ã¢ããªã«ååãä»ãã |
Redirect URI | urn:ietf:wg:oauth:2.0:oob | Authorization codeã®éä»å
ã«ãªãURIãªã®ã§ ãã¹ãç¨ã«ç¨æããã¦ãããã¥ã¼ã®URIã使ã£ã |
Scopes | å¿ é é ç®ã§ã¯ãªãã£ãã®ã§ç©ºç½ã«ãã¾ãã |
å¿
è¦ãªé
ç®ãç»é²ããã¨ã¢ããªã±ã¼ã·ã§ã³ã®ãã¼ã¸ãä½æãããApplication Id
ã¨Secret
ãè¨è¼ããã¦ãã¾ãã
ä½æããã¢ããªã±ã¼ã·ã§ã³ãAuthorizeãã
ã¢ããªã±ã¼ã·ã§ã³ã®ãã¼ã¸ã«ããAuthorize
*3ããRedirect URI
ã«Authorization code
*4ãéä»ãããRedirect URI
ã«è¨è¿°ããURIã«ç§»åãã¾ãã
Redirect URI
ã«ãDoorkeeperã«ç¨æããã¦ãããã¹ãç¨ã®ãã¥ã¼ã®URIã使ç¨ãã¦ããå ´åã¯ãAuthorization code
ãè¨è¼ããããã¼ã¸ã表示ããã¾ãã
cURLã³ãã³ãã§ã¢ã¯ã»ã¹ãã¼ã¯ã³ãåå¾ãã
Access Token
*5ãåå¾ããããã«ã¯ãApplication Id
ã¨Secret
ã¨Authorization code
ãhttp://localhost:3000/oauth/token
ã«éä¿¡ããã®ã§ãããAccess Token
ãåå¾ããããã®ãã©ã¼ã ããã¥ã¼ãç¨æãã¦ã¾ããã®ã§ãcurlã³ãã³ãã使ç¨ãã¦åå¾ãã¾ãã
curl -F grant_type=authorization_code \ -F client_id=9b36d8c0db59eff5038aea7a417d73e69aea75b41aac771816d2ef1b3109cc2f \ -F client_secret=d6ea27703957b69939b8104ed4524595e210cd2e79af587744a7eb6e58f5b3d2 \ -F code=fd0847dbb559752d932dd3c1ac34ff98d27b11fe2fea5a864f44740cd7919ad0 \ -F redirect_uri=urn:ietf:wg:oauth:2.0:oob \ -X POST http://localhost:3000/oauth/token {"access_token":"1d69ea5e8011579d35d16aacec463862855701ed4805f31014b72c2862c18e9d","token_type":"bearer","expires_in":7200,"scope":"public","created_at":1437932641}%
- curl ⦠æå®ããURLã¸ãã¼ã¿ã®éåä¿¡ãè¡ãã³ãã³ã
- -F "name=content" ⦠ãã©ã¼ã ããã®POSTãªã¯ã¨ã¹ãã®ãµãã¾ãã模å£ãããªãã·ã§ã³
- grant_type ⦠`Authorization code`ãéãã®ã§"authorization_code"ãå ¥åãã
- client_it ⦠`Application Id`ãå ¥åãã
- client_secret ⦠`Secret`ãå ¥åãã
- code ⦠`Authorization code`ãå ¥åãã
- redirect_uri ⦠ã¢ããªã±ã¼ã·ã§ã³ã®ä½ææã«ç»é²ãã`Redirect URI`ãå ¥åãã
- -X POST ⦠æå®ããURLã¸ã®éä¿¡ã«ç¨ãããªã¯ã¨ã¹ãã¡ã½ããã«POSTãæå®ãããªãã·ã§ã³
- \ ⦠ã³ãã³ãããªãã·ã§ã³ã®éä¸ã§ä½¿ãã¨æ¹è¡ã§ãã
èªè¨¼ä»ãAPI v1ã®åä½ç¢ºèª
åå¾ããAccess Token
ã¨curl
ã³ãã³ãã§ãèªè¨¼ä»ãAPI v1
ã®åä½ã確èªãã¾ãã
ã¢ã¯ã»ã¹ãã¼ã¯ã³ç¡ãã§ã¯ã¢ã¯ã»ã¹åºæ¥ãªãäºã確èªãã
åç·¨ã§ç¢ºèªããåä½ã試ãã¦ã¿ãã¨ã"The access token is invalid"ã表示ããã¾ãã
$curl http://localhost:3000/api/v1/statuses/ {"error":"The access token is invalid"}% $curl http://localhost:3000/api/v1/statuses/index {"error":"The access token is invalid"}% $curl -d "user_id=2&content=api test" http://localhost:3000/api/v1/statuses {"error":"The access token is invalid"}%
ã¢ã¯ã»ã¹ãã¼ã¯ã³ãéã£ã¦Get the root url
curl
ã³ãã³ãã®-H
ãªãã·ã§ã³ã§ãAuthorizationãªã¯ã¨ã¹ããããã«Bearer
ãªãã¼ã¯ã³ã¨ãã¦Access Token
ãæå®ããroot URLã«ã¢ã¯ã»ã¹ãã¦ã¿ã¾ãã
$curl -H "Authorization: Bearer 1d69ea5e8011579d35d16aacec463862855701ed4805f31014b72c2862c18e9d" http://localhost:3000/api/v1/statuses 200%
ç¡äºã«ãã¹ãã¼ã¿ã¹ã³ã¼ã200
ã表示ããã¾ããã
rails server
ã®ãã°ã§ã¯ãAccess Token
ãæ¤è¨¼ããã¦ããæ§åã確èªã§ãã¾ãã
Started GET "/api/v1/statuses" for ::1 at 2016-06-18 22:13:24 +0900 Doorkeeper::AccessToken Load (0.4ms) SELECT "oauth_access_tokens".* FROM "oauth_access_tokens" WHERE "oauth_access_tokens"."token" = $1 LIMIT 1 [["token", "1d69ea5e8011579d35d16aacec463862855701ed4805f31014b72c2862c18e9d"]] Doorkeeper::AccessToken Load (0.3ms) SELECT "oauth_access_tokens".* FROM "oauth_access_tokens" WHERE "oauth_access_tokens"."refresh_token" = $1 LIMIT 1 [["refresh_token", ""]] (0.2ms) BEGIN (0.2ms) COMMIT
ã¢ã¯ã»ã¹ãã¼ã¯ã³ãéã£ã¦Post new micropost
åæ§ã«ãã¦ãAccess Token
ãç¨ãããã¤ã¯ããã¹ãã®POST
æ©è½ã試ãã¦ã¿ã¾ãã
åç·¨ã§ç¢ºèªããéã«ã¯user_id
ãéä¿¡ãã¦ãã¾ããããAccess Token
ãããªã½ã¼ã¹ãªã¼ãã¼ã®id
ãåå¾ã§ãããããcontent
ã®test api post
ã®ã¿POST
ãã¾ãã
$curl -H "Authorization: Bearer 1d69ea5e8011579d35d16aacec463862855701ed4805f31014b72c2862c18e9d" -d "content=test api post" http://localhost:3000/api/v1/statuses 201%
- curl ⦠æå®ããURLã¸ãã¼ã¿ã®éåä¿¡ãè¡ãã³ãã³ã
- -H "header" ⦠追å ã®ããããéä¿¡ã§ãããªãã·ã§ã³
- -d "name=value" ⦠ãã¼ã¿ãPOSTãªã¯ã¨ã¹ãã¨ãã¦éä¿¡ã§ãããªãã·ã§ã³ã§'&'ã使ã£ã¦è¤æ°é ç®ãã¾ã¨ãã¦éãã
ç¡äºã«ãã¹ãã¼ã¿ã¹ã³ã¼ã201
ã表示ããã¾ããã
rails server
ã®ãã°ã§ããAccess Token
ã®æ¤è¨¼ã¨SQLã®INSERTã確èªã§ãã¾ãã
Started POST "/api/v1/statuses" for ::1 at 2016-06-18 22:15:55 +0900 Doorkeeper::AccessToken Load (0.6ms) SELECT "oauth_access_tokens".* FROM "oauth_access_tokens" WHERE "oauth_access_tokens"."token" = $1 LIMIT 1 [["token", "1d69ea5e8011579d35d16aacec463862855701ed4805f31014b72c2862c18e9d"]] Doorkeeper::AccessToken Load (0.6ms) SELECT "oauth_access_tokens".* FROM "oauth_access_tokens" WHERE "oauth_access_tokens"."refresh_token" = $1 LIMIT 1 [["refresh_token", ""]] (0.5ms) BEGIN (0.3ms) COMMIT (0.3ms) BEGIN SQL (47.3ms) INSERT INTO "microposts" ("user_id", "content", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["user_id", 1], ["content", "test api post"], ["created_at", "2016-06-18 13:15:55.972622"], ["updated_at", "2016-06-18 13:15:55.972622"]] (647.8ms) COMMIT
念ã®ããããã¼ã¿ãã¼ã¹ã確èªãã¦ã¿ã¾ãã
railsapp_development=# SELECT * FROM microposts ORDER BY id DESC LIMIT 1; id | content | user_id | created_at | updated_at -----+---------------+---------+----------------------------+---------------------------- 334 | test api post | 1 | 2016-06-18 13:15:55.972622 | 2016-06-18 13:15:55.972622 (1 row)
ãã£ããã¼ä¿åããã¦ãã¼â ( ï¾Ð´ï¾)ï¼
è足ï¼Strong Parametersã使ã£ã¦Mass Assignmentèå¼±æ§å¯¾çã試ã¿ã
API v1
ã®POST
ã¡ã½ããã§ãMicropost
ã¢ãã«ã«params
ããç´æ¥ãã©ã¡ã¼ã¿ã渡ãã¦ããã®ãè¦ã¦ãã¦ããªã«ããä¸å®ã«ãªã£ã¦ããã®ã§ãããã¡ãã£ã¨è¯ãæ¸ãæ¹ãç¡ããã®ãã¨èª¿ã¹ãæãGrape
ããã§ããRailsã®Strong Parameters
ã使ãããããã¨ç¥ã£ãã®ã§ããã«ãã¼ã¡ã½ããã¨ãã¦helpers
ã®ãããã¯ã«å®ç¾©ãã¦ä½¿ã£ã¦ã¿ã¾ããã
ã¤ãã§ã«ããªã½ã¼ã¹ãªã¼ãã¼ã®id
ããUser
ãªãã¸ã§ã¯ããåå¾ãã¦ãUser
ã¨Micropost
ã®é¢é£ä»ãã使ç¨ãã¦ãã¤ã¯ããã¹ããä½æããã¡ã½ããã使ãããã«ãã¾ããã
module V1 class V1API < Grape::API helpers do include Doorkeeper::Grape::Helpers def owner_user User.find_by_id(doorkeeper_token[:resource_owner_id]) end def content_params ActionController::Parameters.new(params).permit(:content) end end before do doorkeeper_authorize! end resource :statuses do ã» ãããã» ãããã» post do owner_user.microposts.create!(content_params) status 201 end end end end
åèè¨äº
Grapeã«é¢ãã¦ã¯ããã¡ãã®è¨äºãåèã«ããã¦ããã ãã¾ããã
- GitHub - ruby-grape/grape: An opinionated framework for creating REST-like APIs in Ruby.
- Rails x Grapeで簡単API開発 - プログラミングノート
- RailsとGrapeをはじめてつかってみた | Webuilder240
- Grape での mass assignment 対策 - Qiita
Doorkeeperã«é¢ãã¦ã¯ããã¡ãã®è¨äºãåèã«ããã¦ããã ãã¾ããã
- GitHub - doorkeeper-gem/doorkeeper: Doorkeeper is an OAuth 2 provider for Rails
- Rails 4.1 で Doorkeeper を使った OAuth2 Provider のサンプルを実装した - @znz blog
- Rails で API サーバーの認証の仕組みを作る - nirasan's tech blog
- よくわかる認証と認可 | Developers.IO
cURLã«é¢ãã¦ã¯ããã¡ãã®è¨äºãåèã«ããã¦ããã ãã¾ããã
éçºç°å¢
- OSX 10.11.5 El Capitan
- ããã¹ãã¨ãã£ã¿ï¼ MacVim
- ã¿ã¼ããã«ã¨ãã¥ã¬ã¼ã¿ï¼ Macã¿ã¼ããã«
- ã·ã§ã«ï¼ zsh
- ããã±ã¼ã¸ããã¼ã¸ã£ï¼ Homebrew
- ãã©ã¦ã¶ï¼ Firefox - Ruby 2.3.0
- ãã¼ã¸ã§ã³ããã¼ã¸ã£ï¼ rbenv
- Webãã¬ã¼ã ã¯ã¼ã¯ï¼ Ruby on Rails 4.2.6 - ãã¼ã¿ãã¼ã¹
- ORDBMSï¼ PostgreSQL 9.5.1
*1:ã¢ã¯ã»ã¹ãã¼ã¯ã³ãçºè¡ã§ããã¦ã¼ã¶
*2:SessionsHelperã«å®ç¾©ãã¦ããèªè¨¼ã¡ã½ãã
*3:ä½æããã¢ããªã±ã¼ã·ã§ã³ã®ååã®Authorizeã®éã¯AuthorizeãDenyãå確èªããã¾ã
*4:Authorization codeã®æå¹æéã®åæè¨å®å¤ã¯10åã ããã§ã
*5:Access Tokenã®æå¹æéã®åæè¨å®å¤ã¯2æéã ããã§ã