Skip to content

Commit

Permalink
Merge pull request #21 from joneslee85/minor-refactoring
Browse files Browse the repository at this point in the history
Minor refactoring
  • Loading branch information
tbetbetbe committed Apr 14, 2015
2 parents 7e522cf + 66ae035 commit 2924980
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
16 changes: 10 additions & 6 deletions lib/googleauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,14 @@ def self.determine_creds_class(json_key_io)
json_key = MultiJson.load(json_key_io.read)
fail "the json is missing the #{key} field" unless json_key.key?('type')
type = json_key['type']
return json_key, ServiceAccountCredentials if type == 'service_account'
return [json_key, UserRefreshCredentials] if type == 'authorized_user'
fail "credentials type '#{type}' is not supported"
case type
when 'service_account'
[json_key, ServiceAccountCredentials]
when 'authorized_user'
[json_key, UserRefreshCredentials]
else
fail "credentials type '#{type}' is not supported"
end
end
end

Expand All @@ -82,9 +87,8 @@ def self.determine_creds_class(json_key_io)
# @param scope [string|array|nil] the scope(s) to access
# @param options [hash] allows override of the connection being used
def get_application_default(scope = nil, options = {})
creds = DefaultCredentials.from_env(scope)
return creds unless creds.nil?
creds = DefaultCredentials.from_well_known_path(scope)
creds = DefaultCredentials.from_env(scope) ||
DefaultCredentials.from_well_known_path(scope)
return creds unless creds.nil?
fail NOT_FOUND_ERROR unless GCECredentials.on_gce?(options)
GCECredentials.new
Expand Down
3 changes: 1 addition & 2 deletions spec/googleauth/signet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@
scope: 'https://www.googleapis.com/auth/userinfo.profile',
issuer: 'app@example.com',
audience: 'https://accounts.google.com/o/oauth2/token',
signing_key: @key
)
signing_key: @key)
end

def make_auth_stubs(opts)
Expand Down

0 comments on commit 2924980

Please sign in to comment.