Module: Octokit::Client::Authorizations
- Included in:
- Octokit::Client
- Defined in:
- lib/octokit/client/authorizations.rb
Overview
Methods for the Authorizations API
Instance Method Summary collapse
-
#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.
-
#check_application_authorization(token, options = {}) ⇒ Sawyer::Resource
Check if a token is valid.
-
#create_authorization(options = {}) ⇒ Sawyer::Resource
Create an authorization for the authenticated user.
-
#delete_authorization(number, options = {}) ⇒ Boolean
Delete an authorization for the authenticated user.
-
#reset_application_authorization(token, options = {}) ⇒ Sawyer::Resource
Reset a token.
-
#revoke_all_application_authorizations(options = {}) ⇒ Boolean
deprecated
Deprecated.
As of January 25th, 2016: developer.github.com/changes/2014-04-08-reset-api-tokens/
-
#revoke_application_authorization(token, options = {}) ⇒ Boolean
(also: #delete_application_authorization)
Revoke a token.
-
#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.
34 35 36 |
# 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.
20 21 22 |
# 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
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/octokit/client/authorizations.rb', line 233 def (app_id = client_id, = {}) opts = .dup if app_id.to_s.empty? raise Octokit::ApplicationCredentialsRequired.new "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 |
#check_application_authorization(token, options = {}) ⇒ Sawyer::Resource
Check if a token is valid.
Applications can check if a token is valid without rate limits.
154 155 156 157 158 159 160 161 162 |
# File 'lib/octokit/client/authorizations.rb', line 154 def (token, = {}) opts = .dup key = opts.delete(:client_id) || client_id secret = opts.delete(:client_secret) || client_secret as_app(key, secret) do |app_client| app_client.get "applications/#{client_id}/tokens/#{token}", opts 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.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/octokit/client/authorizations.rb', line 61 def ( = {}) # Techincally 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() raise ArgumentError.new("Client ID and Secret required for idempotent authorizations") unless client_id && client_secret # 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.
118 119 120 |
# File 'lib/octokit/client/authorizations.rb', line 118 def (number, = {}) boolean_from_response :delete, "authorizations/#{number}", end |
#reset_application_authorization(token, options = {}) ⇒ Sawyer::Resource
Reset a token
Applications can reset a token without requiring a user to re-authorize.
175 176 177 178 179 180 181 182 183 |
# File 'lib/octokit/client/authorizations.rb', line 175 def (token, = {}) opts = .dup key = opts.delete(:client_id) || client_id secret = opts.delete(:client_secret) || client_secret as_app(key, secret) do |app_client| app_client.post "applications/#{client_id}/tokens/#{token}", opts end end |
#revoke_all_application_authorizations(options = {}) ⇒ Boolean
As of January 25th, 2016: 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
217 218 219 220 |
# File 'lib/octokit/client/authorizations.rb', line 217 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 |
#revoke_application_authorization(token, options = {}) ⇒ Boolean Also known as:
Revoke a token
Applications can revoke (delete) a token
196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/octokit/client/authorizations.rb', line 196 def (token, = {}) opts = .dup key = opts.delete(:client_id) || client_id secret = opts.delete(:client_secret) || client_secret as_app(key, secret) do |app_client| app_client.delete "applications/#{client_id}/tokens/#{token}", opts app_client.last_response.status == 204 end rescue Octokit::NotFound false end |
#scopes(token = @access_token, options = {}) ⇒ Array<String>
Check scopes for a token
128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/octokit/client/authorizations.rb', line 128 def scopes(token = @access_token, = {}) = .dup raise ArgumentError.new("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.
102 103 104 |
# File 'lib/octokit/client/authorizations.rb', line 102 def (number, = {}) patch "authorizations/#{number}", end |