summaryrefslogtreecommitdiff
path: root/lib/google_api
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2017-09-27 21:01:08 +0900
committerShinya Maeda <shinya@gitlab.com>2017-09-27 21:01:08 +0900
commite9d05a2cdc24b4dc771344f26e6ffdcf0240e46c (patch)
tree1aca43cc521894908abb615244927a4d3fc62e70 /lib/google_api
parent9900933432fc05a07b4c3e742c0ec3f295cf773c (diff)
downloadgitlab-ce-e9d05a2cdc24b4dc771344f26e6ffdcf0240e46c.tar.gz
Add login root. Remove ceration type.
Diffstat (limited to 'lib/google_api')
-rw-r--r--lib/google_api/authentication.rb34
1 files changed, 18 insertions, 16 deletions
diff --git a/lib/google_api/authentication.rb b/lib/google_api/authentication.rb
index d7b473525fb..4c9016e1085 100644
--- a/lib/google_api/authentication.rb
+++ b/lib/google_api/authentication.rb
@@ -2,28 +2,14 @@ module GoogleApi
class Authentication
attr_reader :access_token, :redirect_uri, :state
+ ConfigMissingError = Class.new(StandardError)
+
def initialize(access_token, redirect_uri, state: nil)
@access_token = access_token
@redirect_uri = redirect_uri
@state = state
end
- def client
- return @client if defined?(@client)
-
- unless config
- raise 'OAuth configuration for google_oauth2 missing.'
- end
-
- @client = ::OAuth2::Client.new(
- config.app_id,
- config.app_secret,
- site: 'https://accounts.google.com',
- token_url: '/o/oauth2/token',
- authorize_url: '/o/oauth2/auth'
- )
- end
-
def authorize_url
client.auth_code.authorize_url(
redirect_uri: redirect_uri,
@@ -47,5 +33,21 @@ module GoogleApi
def config
Gitlab.config.omniauth.providers.find { |provider| provider.name == "google_oauth2" }
end
+
+ def client
+ return @client if defined?(@client)
+
+ unless config
+ raise ConfigMissingError
+ end
+
+ @client = ::OAuth2::Client.new(
+ config.app_id,
+ config.app_secret,
+ site: 'https://accounts.google.com',
+ token_url: '/o/oauth2/token',
+ authorize_url: '/o/oauth2/auth'
+ )
+ end
end
end