Class: OAuth::Provider::Authorizer
- Inherits:
-
Object
- Object
- OAuth::Provider::Authorizer
- Defined in:
- lib/oauth/provider/authorizer.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#params ⇒ Object
Returns the value of attribute params.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #authorized? ⇒ Boolean
- #code ⇒ Object
- #encode_response ⇒ Object
-
#initialize(user, authorized, params = {}) ⇒ Authorizer
constructor
A new instance of Authorizer.
- #redirect_uri ⇒ Object
- #response ⇒ Object
- #token ⇒ Object
Constructor Details
#initialize(user, authorized, params = {}) ⇒ Authorizer
Returns a new instance of Authorizer.
8 9 10 11 12 |
# File 'lib/oauth/provider/authorizer.rb', line 8 def initialize(user, , params = {}) @user = user @params = params @authorized = end |
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
6 7 8 |
# File 'lib/oauth/provider/authorizer.rb', line 6 def app @app end |
#params ⇒ Object
Returns the value of attribute params.
6 7 8 |
# File 'lib/oauth/provider/authorizer.rb', line 6 def params @params end |
#user ⇒ Object
Returns the value of attribute user.
6 7 8 |
# File 'lib/oauth/provider/authorizer.rb', line 6 def user @user end |
Instance Method Details
#authorized? ⇒ Boolean
32 33 34 |
# File 'lib/oauth/provider/authorizer.rb', line 32 def @authorized == true end |
#code ⇒ Object
18 19 20 21 22 23 |
# File 'lib/oauth/provider/authorizer.rb', line 18 def code @code ||= ::Oauth2Verifier.create! :client_application => app, :user => @user, :scope => @params[:scope], :callback_url => @params[:redirect_uri] end |
#encode_response ⇒ Object
70 71 72 73 74 |
# File 'lib/oauth/provider/authorizer.rb', line 70 def encode_response response.map do |k, v| [URI.escape(k.to_s),URI.escape(v)] * "=" end * "&" end |
#redirect_uri ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/oauth/provider/authorizer.rb', line 36 def redirect_uri uri = base_uri if params[:response_type] == 'code' if uri.query uri.query << '&' else uri.query = '' end uri.query << encode_response else uri.fragment = encode_response end uri.to_s end |
#response ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/oauth/provider/authorizer.rb', line 51 def response r = {} if ['token','code'].include? params[:response_type] if if params[:response_type] == 'code' r[:code] = code.token else r[:access_token] = token.token end else r[:error] = 'access_denied' end else r[:error] = 'unsupported_response_type' end r[:state] = params[:state] if params[:state] r end |
#token ⇒ Object
25 26 27 28 29 30 |
# File 'lib/oauth/provider/authorizer.rb', line 25 def token @token ||= ::Oauth2Token.create! :client_application => app, :user => @user, :scope => @params[:scope], :callback_url => @params[:redirect_uri] end |