Module: EasyAuth::Models::Identities::OauthCore::ClassMethods

Defined in:
lib/easy_auth/models/identities/oauth_core.rb

Instance Method Summary collapse

Instance Method Details

#account_attributes(account_attributes, identity) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/easy_auth/models/identities/oauth_core.rb', line 59

def (, identity)
  EasyAuth..define_attribute_methods unless EasyAuth..attribute_methods_generated?
  setters = EasyAuth..instance_methods.grep(/=$/) - [:id=]

  attributes = .inject({}) do |hash, kv|
    if setters.include?("#{kv[0]}=".to_sym)
      hash[kv[0]] = [kv[1]]
    end

    hash
  end

  attributes[:identities_attributes] = [
    { uid: identity.uid, token: identity.token, type: identity.class.model_name.to_s }
  ]

  return attributes
end

#account_attributes_mapObject



78
79
80
# File 'lib/easy_auth/models/identities/oauth_core.rb', line 78

def 
  { :email => 'email' }
end

#authenticate(controller) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/easy_auth/models/identities/oauth_core.rb', line 5

def authenticate(controller)
  if can_authenticate?(controller)
    identity,  = *yield

    if controller.
      (identity, controller, )
    else
      (identity, controller, )
    end
  end
end

#can_authenticate?(controller) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


55
56
57
# File 'lib/easy_auth/models/identities/oauth_core.rb', line 55

def can_authenticate?(controller)
  raise NotImplementedError
end

#client_idObject



82
83
84
# File 'lib/easy_auth/models/identities/oauth_core.rb', line 82

def client_id
  settings.client_id
end

#providerObject



94
95
96
# File 'lib/easy_auth/models/identities/oauth_core.rb', line 94

def provider
  self.to_s.split('::').last.underscore.to_sym
end

#retrieve_uid(account_attributes) ⇒ Object

Raises:

  • (NotImplementedError)


98
99
100
# File 'lib/easy_auth/models/identities/oauth_core.rb', line 98

def retrieve_uid()
  raise NotImplementedError
end

#secretObject



86
87
88
# File 'lib/easy_auth/models/identities/oauth_core.rb', line 86

def secret
  settings.secret
end

#settingsObject



90
91
92
# File 'lib/easy_auth/models/identities/oauth_core.rb', line 90

def settings
  EasyAuth.send(version)[provider]
end

#with_account(identity, controller, account_attributes) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/easy_auth/models/identities/oauth_core.rb', line 17

def (identity, controller, )
  if identity.
    if identity. != controller.
      controller.flash[:error] = I18n.t('easy_auth.oauth2.sessions.create.error')
      return nil
    end
  else
    identity. = controller.
  end

  identity.save!

  return identity
end

#without_account(identity, controller, account_attributes) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/easy_auth/models/identities/oauth_core.rb', line 32

def (identity, controller, )
  if identity.
    return identity
  else
     = EasyAuth..model_name
    env = clean_env(controller.env.dup)

    env['QUERY_STRING'] = {.param_key => (, identity)}.to_param

     = ActiveSupport::Dependencies.constantize("#{.route_key.camelize}Controller")
     = .new
    .dispatch(:create, ActionDispatch::Request.new(env))

    controller.status = .status
    controller.location = .location
    controller.content_type = .content_type
    controller.response_body = .response_body
    controller.request.session = .session

    return nil
  end
end