Class: OauthController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- OauthController
- Defined in:
- app/controllers/oauth_controller.rb
Instance Method Summary collapse
Instance Method Details
#access_token ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/controllers/oauth_controller.rb', line 45 def access_token token = params.fetch(:oauth_token, oauth_params.fetch("oauth_token")) @request_token = OauthProviderEngine::RequestToken..where(:token => token).first # ensure we have a valid request token return render_403("invalid request token") unless @request_token # ensure that the OAuth request was properly signed return render_401("invalid signature") unless OAuth::Signature.verify(oauth_request, :consumer_secret => @application.secret, :token_secret => @request_token.secret) if @access_token = OauthProviderEngine::AccessToken.not_expired.for_user(@request_token.user_id).first # user already has a valid access token @request_token.destroy else # upgrade the request token to an access token (deletes the request token) @access_token = @request_token.upgrade! end render :text => @access_token.to_query end |
#authorize ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/oauth_controller.rb', line 11 def # ensure we have a valid request token @request_token = OauthProviderEngine::RequestToken.where(:token => params[:oauth_token]).first return render_403("invalid request token") unless @request_token # check to see if the user has already authorized user_id = OauthProviderEngine.user_method.call(self) if @access_token = OauthProviderEngine::AccessToken.not_expired.for_user(user_id).first @request_token.(user_id) (@request_token) return end if request.post? # create an access token for the current user @request_token.(user_id) (@request_token) else # render the allow/disallow form @application = @request_token.application render :authorize, :layout => OauthProviderEngine.oauth_layout end end |
#request_token ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'app/controllers/oauth_controller.rb', line 35 def request_token # ensure that the OAuth request was properly signed return render_401("invalid signature") unless OAuth::Signature.verify(oauth_request, :consumer_secret => @application.secret) @request_token = @application.request_tokens.build() @request_token.save render :text => @request_token.to_query end |