Module: Github::Authorization
- Included in:
- API
- Defined in:
- lib/github_api2/authorization.rb
Instance Method Summary collapse
-
#auth_code ⇒ Object
Strategy token.
-
#authenticated? ⇒ Boolean
Check whether authentication credentials are present.
-
#authentication ⇒ Object
Select authentication parameters.
-
#authorize_url(params = {}) ⇒ Object
Sends authorization request to GitHub.
-
#basic_authed? ⇒ Boolean
Check whether basic authentication credentials are present.
-
#client ⇒ Object
Setup OAuth2 instance.
-
#get_token(authorization_code, params = {}) ⇒ Object
Makes request to token endpoint and retrieves access token value.
Instance Method Details
#auth_code ⇒ Object
Strategy token
21 22 23 24 |
# File 'lib/github_api2/authorization.rb', line 21 def auth_code _verify_client client.auth_code end |
#authenticated? ⇒ Boolean
Check whether authentication credentials are present
49 50 51 |
# File 'lib/github_api2/authorization.rb', line 49 def authenticated? basic_authed? || oauth_token? end |
#authentication ⇒ Object
Select authentication parameters
61 62 63 64 65 66 67 |
# File 'lib/github_api2/authorization.rb', line 61 def authentication if basic_authed? { login: login, password: password } else {} end end |
#authorize_url(params = {}) ⇒ Object
Sends authorization request to GitHub.
Parameters
-
:redirect_uri
- Optional string. -
:scope
- Optional string. Comma separated list of scopes. Available scopes:-
(no scope) - public read-only access (includes public user profile info, public repo info, and gists).
-
user
- DB read/write access to profile info only. -
public_repo
- DB read/write access, and Git read access to public repos. -
repo
- DB read/write access, and Git read access to public and private repos. -
gist
- write access to gists.
-
37 38 39 40 |
# File 'lib/github_api2/authorization.rb', line 37 def (params = {}) _verify_client client.auth_code.(params) end |
#basic_authed? ⇒ Boolean
Check whether basic authentication credentials are present
54 55 56 |
# File 'lib/github_api2/authorization.rb', line 54 def basic_authed? basic_auth? || (login? && password?) end |
#client ⇒ Object
Setup OAuth2 instance
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/github_api2/authorization.rb', line 9 def client @client ||= ::OAuth2::Client.new(client_id, client_secret, { :site => .fetch(:site) { Github.site }, :authorize_url => 'login/oauth/authorize', :token_url => 'login/oauth/access_token', :ssl => { :verify => false } } ) end |
#get_token(authorization_code, params = {}) ⇒ Object
Makes request to token endpoint and retrieves access token value
43 44 45 46 |
# File 'lib/github_api2/authorization.rb', line 43 def get_token(, params = {}) _verify_client client.auth_code.get_token(, params) end |