Module: EasyAuth::Models::Identities::Oauth2::Base::ClassMethods
- Defined in:
- lib/easy_auth/models/identities/oauth2/base.rb
Instance Method Summary collapse
- #account_attributes_url ⇒ Object
- #authenticate(controller) ⇒ Object
- #authenticate_url(callback_url) ⇒ Object
- #authorize_url ⇒ Object
- #can_authenticate?(controller) ⇒ Boolean
- #client ⇒ Object
- #get_access_token(identity) ⇒ Object
- #get_account_attributes(token) ⇒ Object
- #new_session(controller) ⇒ Object
- #oauth2_scope ⇒ Object
- #site_url ⇒ Object
- #token_options(callback_url) ⇒ Object
-
#token_params ⇒ Object
Needed by some OAuth2 providers the use custom query parameters.
- #token_url ⇒ Object
- #version ⇒ Object
Instance Method Details
#account_attributes_url ⇒ Object
63 64 65 |
# File 'lib/easy_auth/models/identities/oauth2/base.rb', line 63 def account_attributes_url raise NotImplementedError end |
#authenticate(controller) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/easy_auth/models/identities/oauth2/base.rb', line 9 def authenticate(controller) super(controller) do callback_url = controller.oauth2_callback_url(:provider => provider) code = controller.params[:code] token = client.auth_code.get_token(code, (callback_url), token_params) account_attributes = get_account_attributes(token) identity = self.find_or_initialize_by(:uid => retrieve_uid(account_attributes)) identity.token = token.token [identity, account_attributes] end end |
#authenticate_url(callback_url) ⇒ Object
59 60 61 |
# File 'lib/easy_auth/models/identities/oauth2/base.rb', line 59 def authenticate_url(callback_url) client.auth_code.(:redirect_uri => callback_url, :scope => oauth2_scope) end |
#authorize_url ⇒ Object
67 68 69 |
# File 'lib/easy_auth/models/identities/oauth2/base.rb', line 67 def raise NotImplementedError end |
#can_authenticate?(controller) ⇒ Boolean
26 27 28 |
# File 'lib/easy_auth/models/identities/oauth2/base.rb', line 26 def can_authenticate?(controller) controller.params[:code].present? && controller.params[:error].blank? end |
#client ⇒ Object
55 56 57 |
# File 'lib/easy_auth/models/identities/oauth2/base.rb', line 55 def client @client ||= ::OAuth2::Client.new(client_id, secret, :site => site_url, :authorize_url => , :token_url => token_url) end |
#get_access_token(identity) ⇒ Object
30 31 32 |
# File 'lib/easy_auth/models/identities/oauth2/base.rb', line 30 def get_access_token(identity) ::OAuth2::AccessToken.new client, identity.token end |
#get_account_attributes(token) ⇒ Object
51 52 53 |
# File 'lib/easy_auth/models/identities/oauth2/base.rb', line 51 def get_account_attributes(token) ActiveSupport::JSON.decode(token.get(account_attributes_url).body) end |
#new_session(controller) ⇒ Object
22 23 24 |
# File 'lib/easy_auth/models/identities/oauth2/base.rb', line 22 def new_session(controller) controller.redirect_to authenticate_url(controller.oauth2_callback_url(:provider => provider)) end |
#oauth2_scope ⇒ Object
38 39 40 |
# File 'lib/easy_auth/models/identities/oauth2/base.rb', line 38 def oauth2_scope '' end |
#site_url ⇒ Object
75 76 77 |
# File 'lib/easy_auth/models/identities/oauth2/base.rb', line 75 def site_url raise NotImplementedError end |
#token_options(callback_url) ⇒ Object
42 43 44 |
# File 'lib/easy_auth/models/identities/oauth2/base.rb', line 42 def (callback_url) { :redirect_uri => callback_url } end |
#token_params ⇒ Object
Needed by some OAuth2 providers the use custom query parameters
47 48 49 |
# File 'lib/easy_auth/models/identities/oauth2/base.rb', line 47 def token_params {} end |
#token_url ⇒ Object
71 72 73 |
# File 'lib/easy_auth/models/identities/oauth2/base.rb', line 71 def token_url raise NotImplementedError end |
#version ⇒ Object
34 35 36 |
# File 'lib/easy_auth/models/identities/oauth2/base.rb', line 34 def version :oauth2 end |