Module: Sorcery::Controller::Submodules::External::Providers::Github::GithubClient

Extended by:
Sorcery::Controller::Submodules::External::Protocols::Oauth2
Defined in:
lib/sorcery/controller/submodules/external/providers/github.rb

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Sorcery::Controller::Submodules::External::Protocols::Oauth2

authorize_url, build_client, get_access_token, oauth_version

Class Attribute Details

.access_tokenObject (readonly)

Returns the value of attribute access_token.



39
40
41
# File 'lib/sorcery/controller/submodules/external/providers/github.rb', line 39

def access_token
  @access_token
end

.auth_pathObject

Returns the value of attribute auth_path.



31
32
33
# File 'lib/sorcery/controller/submodules/external/providers/github.rb', line 31

def auth_path
  @auth_path
end

.callback_urlObject

Returns the value of attribute callback_url.



31
32
33
# File 'lib/sorcery/controller/submodules/external/providers/github.rb', line 31

def callback_url
  @callback_url
end

.keyObject

Returns the value of attribute key.



31
32
33
# File 'lib/sorcery/controller/submodules/external/providers/github.rb', line 31

def key
  @key
end

.secretObject

Returns the value of attribute secret.



31
32
33
# File 'lib/sorcery/controller/submodules/external/providers/github.rb', line 31

def secret
  @secret
end

.siteObject

Returns the value of attribute site.



31
32
33
# File 'lib/sorcery/controller/submodules/external/providers/github.rb', line 31

def site
  @site
end

.token_pathObject

Returns the value of attribute token_path.



31
32
33
# File 'lib/sorcery/controller/submodules/external/providers/github.rb', line 31

def token_path
  @token_path
end

.user_info_mappingObject

Returns the value of attribute user_info_mapping.



31
32
33
# File 'lib/sorcery/controller/submodules/external/providers/github.rb', line 31

def 
  @user_info_mapping
end

.user_info_pathObject

Returns the value of attribute user_info_path.



31
32
33
# File 'lib/sorcery/controller/submodules/external/providers/github.rb', line 31

def 
  @user_info_path
end

Class Method Details

.get_user_hashObject



51
52
53
54
55
56
57
# File 'lib/sorcery/controller/submodules/external/providers/github.rb', line 51

def get_user_hash
  user_hash = {}
  response = @access_token.get(@user_info_path)
  user_hash[:user_info] = JSON.parse(response.body)
  user_hash[:uid] = user_hash[:user_info]['id']
  user_hash
end

.has_callback?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/sorcery/controller/submodules/external/providers/github.rb', line 59

def has_callback?
  true
end

.initObject



43
44
45
46
47
48
49
# File 'lib/sorcery/controller/submodules/external/providers/github.rb', line 43

def init
  @site           = "https://github.com/"
  @user_info_path = "https://api.github.com/user"
  @auth_path      = "/login/oauth/authorize"
  @token_path     = "/login/oauth/access_token"
  @user_info_mapping = {}
end

.login_url(params, session) ⇒ Object

calculates and returns the url to which the user should be redirected, to get authenticated at the external provider’s site.



65
66
67
# File 'lib/sorcery/controller/submodules/external/providers/github.rb', line 65

def (params,session)
  self.authorize_url({:authorize_url => @auth_path})
end

.process_callback(params, session) ⇒ Object

tries to login the user from access token



70
71
72
73
74
75
76
77
78
# File 'lib/sorcery/controller/submodules/external/providers/github.rb', line 70

def process_callback(params,session)
  args = {}
  args.merge!({:code => params[:code]}) if params[:code]
  options = {
    :token_url    => @token_path,
    :token_method => :post
  }
  @access_token = self.get_access_token(args, options)
end