Class: Clavis::Providers::Github
- Inherits:
-
Base
- Object
- Base
- Clavis::Providers::Github
show all
- Defined in:
- lib/clavis/providers/github.rb
Instance Attribute Summary
Attributes inherited from Base
#authorize_endpoint_url, #client_id, #client_secret, #provider_name, #redirect_uri, #scope, #token_endpoint_url, #userinfo_endpoint_url
Instance Method Summary
collapse
Methods inherited from Base
#authorize_url, #openid_provider?, #process_callback, #refresh_token, #token_exchange
#build_token_exchange_params, #handle_connection_error, #handle_error_response, #handle_faraday_error, #handle_parser_error, #handle_standard_error, #make_token_request, #parse_response, #skip_error_for_test?, #test_token_response, #validate_and_clean_code
Constructor Details
#initialize(config = {}) ⇒ Github
Returns a new instance of Github.
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/clavis/providers/github.rb', line 6
def initialize(config = {})
site_url = config[:site_url] || "https://api.github.com"
auth_url = config[:authorize_url] || "https://github.com/login/oauth/authorize"
token_url = config[:token_url] || "https://github.com/login/oauth/access_token"
config[:authorization_endpoint] = auth_url
config[:token_endpoint] = token_url
config[:userinfo_endpoint] = "#{site_url}/user"
config[:scope] = config[:scope] || "user:email"
@site_url = site_url
super
end
|
Instance Method Details
#authorization_endpoint ⇒ Object
23
24
25
|
# File 'lib/clavis/providers/github.rb', line 23
def authorization_endpoint
@config[:authorization_endpoint]
end
|
#default_scopes ⇒ Object
35
36
37
|
# File 'lib/clavis/providers/github.rb', line 35
def default_scopes
"user:email"
end
|
#get_user_info(access_token) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/clavis/providers/github.rb', line 39
def get_user_info(access_token)
return {} unless userinfo_endpoint
raise Clavis::InvalidToken unless Clavis::Security::InputValidator.valid_token?(access_token)
response = http_client.get(userinfo_endpoint) do |req|
req.["Authorization"] = "Bearer #{access_token}"
req.["Accept"] = "application/vnd.github.v3+json"
end
if response.status != 200
Clavis::Logging.log_userinfo_request(provider_name, false)
handle_userinfo_error_response(response)
end
Clavis::Logging.log_userinfo_request(provider_name, true)
process_userinfo_response(response)
end
|
#token_endpoint ⇒ Object
27
28
29
|
# File 'lib/clavis/providers/github.rb', line 27
def token_endpoint
@config[:token_endpoint]
end
|
#userinfo_endpoint ⇒ Object
31
32
33
|
# File 'lib/clavis/providers/github.rb', line 31
def userinfo_endpoint
@config[:userinfo_endpoint]
end
|