Module: Octokit::Client::Authorizations
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | lib/octokit/client/authorizations.rb |
Overview
Methods for the Authorizations
API
Instance Method Summary
-
#authorization(number, options = {}) ⇒ Sawyer::Resource
Get a single authorization for the authenticated user.
-
#authorizations(options = {}) ⇒ Array<Sawyer::Resource>
List the authenticated user's authorizations.
-
#authorize_url(app_id = client_id, options = {}) ⇒ String
Get the URL to authorize a user for an application via the web flow.
-
#create_authorization(options = {}) ⇒ Sawyer::Resource
Create an authorization for the authenticated user.
-
#delete_authorization(number, options = {}) ⇒ Boolean
Delete an authorization for the authenticated user.
-
#revoke_all_application_authorizations(_options = {}) ⇒ Boolean
deprecated
Deprecated.
As of January 25th, 2016: https://developer.github.com/changes/2014-04-08-reset-api-tokens/
-
#scopes(token = @access_token, options = {}) ⇒ Array<String>
Check scopes for a token.
-
#update_authorization(number, options = {}) ⇒ Sawyer::Resource
Update an authorization for the authenticated user.
Instance Method Details
#authorization(number, options = {}) ⇒ Sawyer::Resource
Get a single authorization for the authenticated user.
You can only access your own tokens, and only through Basic Authentication.
# File 'lib/octokit/client/authorizations.rb', line 34
def (number, = {}) get "authorizations/#{number}", end
#authorizations(options = {}) ⇒ Array
<Sawyer::Resource
>
List the authenticated user's authorizations
API for users to manage their own tokens. You can only access your own tokens, and only through Basic Authentication.
# File 'lib/octokit/client/authorizations.rb', line 20
def ( = {}) paginate 'authorizations', end
#authorize_url(app_id = client_id, options = {}) ⇒ String
Get the URL to authorize a user for an application via the web flow
# File 'lib/octokit/client/authorizations.rb', line 167
def (app_id = client_id, = {}) opts = .dup if app_id.to_s.empty? raise Octokit::ApplicationCredentialsRequired, 'client_id required' end = opts.delete(:endpoint) || Octokit.web_endpoint << "login/oauth/authorize?client_id=#{app_id}" require 'cgi' opts.each do |key, value| << "&#{key}=#{CGI.escape value}" end end
#create_authorization(options = {}) ⇒ Sawyer::Resource
Create an authorization for the authenticated user.
You can create your own tokens, and only through Basic Authentication.
# File 'lib/octokit/client/authorizations.rb', line 61
def ( = {}) # Technically we can omit scopes as GitHub has a default, however the # API will reject us if we send a POST request with an empty body. = .dup if .delete :idempotent client_id, client_secret = fetch_client_id_and_secret( ) unless client_id && client_secret raise ArgumentError, 'Client ID and Secret required for idempotent authorizations' end # Remove the client_id from the body otherwise # this will result in a 422. .delete(:client_id) if (fingerprint = .delete(:fingerprint)) put "authorizations/clients/#{client_id}/#{fingerprint}", .merge(client_secret: client_secret) else put "authorizations/clients/#{client_id}", .merge(client_secret: client_secret) end else post 'authorizations', end end
#delete_authorization(number, options = {}) ⇒ Boolean
Delete an authorization for the authenticated user.
You can delete your own tokens, and only through Basic Authentication.
# File 'lib/octokit/client/authorizations.rb', line 120
def (number, = {}) boolean_from_response :delete, "authorizations/#{number}", end
#revoke_all_application_authorizations(_options = {}) ⇒ Boolean
As of January 25th, 2016: https://developer.github.com/changes/2014-04-08-reset-api-tokens/
Revoke all tokens for an app
Applications can revoke all of their tokens in a single request
# File 'lib/octokit/client/authorizations.rb', line 151
def ( = {}) octokit_warn('Deprecated: If you need to revoke all tokens for your application, you can do so via the settings page for your application.') false end
#scopes(token = @access_token, options = {}) ⇒ Array
<String
>
Check scopes for a token
# File 'lib/octokit/client/authorizations.rb', line 130
def scopes(token = @access_token, = {}) = .dup raise ArgumentError, 'Access token required' if token.nil? auth = { 'Authorization' => "token #{token}" } headers = ( .delete(:headers) || {}).merge(auth) agent.call(:get, 'user', headers: headers) .headers['X-OAuth-Scopes'] .to_s .split(',') .map(&:strip) .sort end
#update_authorization(number, options = {}) ⇒ Sawyer::Resource
Update an authorization for the authenticated user.
You can update your own tokens, but only through Basic Authentication.
# File 'lib/octokit/client/authorizations.rb', line 104
def (number, = {}) patch "authorizations/#{number}", end