Module: Octokit::Client::OauthApplications

Included in:
Octokit::Client
Defined in:
lib/octokit/client/oauth_applications.rb

Overview

Methods for the OauthApplications API

Instance Method Summary collapse

Instance Method Details

#check_token(access_token, options = {}) ⇒ Sawyer::Resource Also known as: check_application_authorization

Check if a token is valid.

Applications can check if a token is valid without rate limits.

Examples:

client = Octokit::Client.new(:client_id => 'abcdefg12345', :client_secret => 'secret')
client.check_token('deadbeef1234567890deadbeef987654321')

Parameters:

  • access_token (String)

    40 character GitHub OAuth access token

Returns:

  • (Sawyer::Resource)

    A single authorization for the authenticated user

See Also:


23
24
25
26
27
28
29
30
31
32
33
# File 'lib/octokit/client/oauth_applications.rb', line 23

def check_token(access_token, options = {})
  options = ensure_api_media_type(:applications_api, options.dup)
  options[:access_token] = access_token

  key    = options.delete(:client_id)     || client_id
  secret = options.delete(:client_secret) || client_secret

  as_app(key, secret) do |app_client|
    app_client.post "applications/#{client_id}/token", options
  end
end

#delete_app_authorization(access_token, options = {}) ⇒ Boolean

Delete an app authorization

OAuth application owners can revoke a grant for their OAuth application and a specific user.

Examples:

client = Octokit::Client.new(:client_id => 'abcdefg12345', :client_secret => 'secret')
client.delete_app_authorization('deadbeef1234567890deadbeef987654321')

Parameters:

  • access_token (String)

    40 character GitHub OAuth access token

Returns:

  • (Boolean)

    Result

See Also:


104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/octokit/client/oauth_applications.rb', line 104

def delete_app_authorization(access_token, options = {})
  options = ensure_api_media_type(:applications_api, options.dup)
  options[:access_token] = access_token

  key    = options.delete(:client_id)     || client_id
  secret = options.delete(:client_secret) || client_secret

  begin
    as_app(key, secret) do |app_client|
      app_client.delete "applications/#{client_id}/grant", options
      app_client.last_response.status == 204
    end
  rescue Octokit::NotFound
    false
  end
end

#delete_app_token(access_token, options = {}) ⇒ Boolean Also known as: delete_application_authorization, revoke_application_authorization

Delete an app token

Applications can revoke (delete) a token

Examples:

client = Octokit::Client.new(:client_id => 'abcdefg12345', :client_secret => 'secret')
client.delete_token('deadbeef1234567890deadbeef987654321')

Parameters:

  • access_token (String)

    40 character GitHub OAuth access token

Returns:

  • (Boolean)

    Result

See Also:


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/octokit/client/oauth_applications.rb', line 73

def delete_app_token(access_token, options = {})
  options = ensure_api_media_type(:applications_api, options.dup)
  options[:access_token] = access_token

  key    = options.delete(:client_id)     || client_id
  secret = options.delete(:client_secret) || client_secret

  begin
    as_app(key, secret) do |app_client|
      app_client.delete "applications/#{client_id}/token", options
      app_client.last_response.status == 204
    end
  rescue Octokit::NotFound
    false
  end
end

#reset_token(access_token, options = {}) ⇒ Sawyer::Resource Also known as: reset_application_authorization

Reset a token

Applications can reset a token without requiring a user to re-authorize.

Examples:

client = Octokit::Client.new(:client_id => 'abcdefg12345', :client_secret => 'secret')
client.reset_token('deadbeef1234567890deadbeef987654321')

Parameters:

  • access_token (String)

    40 character GitHub OAuth access token

Returns:

  • (Sawyer::Resource)

    A single authorization for the authenticated user

See Also:


48
49
50
51
52
53
54
55
56
57
58
# File 'lib/octokit/client/oauth_applications.rb', line 48

def reset_token(access_token, options = {})
  options = ensure_api_media_type(:applications_api, options.dup)
  options[:access_token] = access_token

  key    = options.delete(:client_id)     || client_id
  secret = options.delete(:client_secret) || client_secret

  as_app(key, secret) do |app_client|
    app_client.patch "applications/#{client_id}/token", options
  end
end