Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add validate_credentials method

Just for @jbarnette
  • Loading branch information...
commit 6cb40b8b48bb4f0b688c010338e5b409724eff8c 1 parent ae64322
@pengwynn pengwynn authored
View
6 lib/octokit/client/authorizations.rb
@@ -96,7 +96,11 @@ def delete_authorization(number, option={})
request(:delete, "authorizations/#{number}").status == 204
end
-
+ # Check scopes for a token
+ #
+ # @param token [String] GitHub OAuth token
+ # @return [Array<String>] OAuth scopes
+ # @see http://developer.github.com/v3/oauth/#scopes
def scopes(token=nil)
request(:get, "user", :access_token => token).
headers[:x_oauth_scopes].
View
14 lib/octokit/client/users.rb
@@ -28,6 +28,20 @@ def user(user=nil)
end
end
+ # Validate user username and password
+ #
+ # @param options [Hash] User credentials
+ # @option options [String] :login GitHub login
+ # @option options [String] :password GitHub password
+ # @return [Boolean] True if credentials are valid
+ def validate_credentials(options = {})
+ begin
+ !self.class.new(options).user.nil?
+ rescue Octokit::Unauthorized
+ false
+ end
+ end
+
# Update the authenticated user
#
# @param options [Hash] A customizable set of options.
View
9 spec/octokit/client/users_spec.rb
@@ -48,6 +48,15 @@
end
+ describe ".validate_credentials" do
+ it "validates username and password" do
+ stub_get("https://sferik:foobar@api.github.com/user").
+ to_return(json_response("user.json"))
+
+ expect(Octokit.validate_credentials(:login => 'sferik', :password => 'foobar')).to eq(true)
+ end
+ end
+
describe ".update_user" do
context "with a location passed" do
Please sign in to comment.
Something went wrong with that request. Please try again.