Module: Rack::OAuth::Methods

Defined in:
lib/rack-oauth.rb

Overview

Helper methods intended to be included in your Rails controller or in your Sinatra helpers block

Instance Method Summary collapse

Instance Method Details

#get_access_token(name = nil) ⇒ Object

This is the method you want to call.

After you’re authorized and redirected back to your #redirect_to path, you should be able to call get_access_token to get and hold onto the access token for the user you’ve been authorized as.

You can use the token to make GET/POST/etc requests



41
42
43
# File 'lib/rack-oauth.rb', line 41

def get_access_token name = nil
  oauth_instance(name).get_access_token(oauth_request_env)
end

#get_access_token!(name = nil) ⇒ Object

Same as #get_access_token but it clears the access token out of the session.



46
47
48
# File 'lib/rack-oauth.rb', line 46

def get_access_token! name = nil
  oauth_instance(name).get_access_token!(oauth_request_env)
end

#oauth_instance(name = nil) ⇒ Object

Returns the instance of Rack::OAuth given a name (defaults to the default Rack::OAuth name)



66
67
68
69
70
# File 'lib/rack-oauth.rb', line 66

def oauth_instance name = nil
  oauth = Rack::OAuth.get(oauth_request_env, nil)
  raise "Couldn't find Rack::OAuth instance with name #{ name }" unless oauth
  oauth
end

#oauth_login_path(name = nil) ⇒ Object

Returns the path to rediret to for logging in via OAuth



73
74
75
# File 'lib/rack-oauth.rb', line 73

def  name = nil
  oauth_instance(name).
end

#oauth_request_envObject

Internal

this method returns the Rack ‘env’ for the current request.

This looks for #env or #request.env by default. If these don’t return something, then we raise an exception and you should override this method so it returns the Rack env that we need.



55
56
57
58
59
60
61
62
63
# File 'lib/rack-oauth.rb', line 55

def oauth_request_env
  if respond_to?(:env)
    env
  elsif respond_to?(:request) and request.respond_to?(:env)
    request.env
  else
    raise "Couldn't find 'env' ... please override #oauth_request_env"
  end
end