public
Last active

Rack::OAuth2::Client Sample - Authorization Request

  • Download Gist
authorization_request_sample.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
require 'rubygems'
require 'rack/oauth2'
 
client = Rack::OAuth2::Client.new(
:identifier => YOUR_CLIENT_ID,
:secret => YOUR_CLIENT_SECRET,
:redirect_uri => YOUR_REDIRECT_URI, # only required for grant_type = :code
:host => 'rack-oauth2-sample.heroku.com'
)
 
request_type = :token
 
puts "## request_type = :#{request_type}"
 
authorization_uri = case request_type
when :code
client.authorization_uri(:scope => :user_about_me)
when :token
client.authorization_uri(:response_type => :token, :scope => :user_about_me)
end
 
puts authorization_uri

I don't know how to use and test the client sample. In order to exec the example above, I must have the consts: YOUR_CLIENT_ID,YOUR_CLIENT_SECRET and so on. But where should I register and get the values.

@zhangyuxiu You need a OAuth 2.0 provider, which can be built by rack-oauth2 or any other OAuth2 provider libraries. For example, you can use the Doorkeeper or devise_oauth2_providable.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.