google_auth_bridge 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/lib/google_auth_bridge.rb +13 -5
- data/lib/google_auth_bridge/version.rb +1 -1
- metadata +4 -4
data/.gitignore
CHANGED
data/lib/google_auth_bridge.rb
CHANGED
@@ -6,15 +6,19 @@ module GoogleAuthenticationBridge
|
|
6
6
|
GOOGLE_REDIRECT_URI = 'urn:ietf:wg:oauth:2.0:oob'
|
7
7
|
|
8
8
|
def self.create_from_config_file(scope, file_name, token_file)
|
9
|
-
config =
|
9
|
+
config = load_file(file_name)
|
10
10
|
client_id, client_secret = config[:google_client_id], config[:google_client_secret]
|
11
|
-
raise InvalidFileFormatError.new(
|
11
|
+
raise InvalidFileFormatError.new(token_file) if client_id.nil? or client_secret.nil?
|
12
12
|
GoogleAuthentication.new(
|
13
13
|
scope,
|
14
14
|
client_id,
|
15
15
|
client_secret,
|
16
16
|
token_file)
|
17
17
|
end
|
18
|
+
|
19
|
+
def self.load_file(file_name)
|
20
|
+
YAML.load_file(file_name)
|
21
|
+
end
|
18
22
|
|
19
23
|
def initialize(scope, client_id, client_secret, token_file)
|
20
24
|
@scope = scope
|
@@ -23,6 +27,10 @@ module GoogleAuthenticationBridge
|
|
23
27
|
@token_file = token_file
|
24
28
|
end
|
25
29
|
|
30
|
+
def token_file_exists?
|
31
|
+
File.exists? @token_file
|
32
|
+
end
|
33
|
+
|
26
34
|
def get_tokens(authorization_code=nil)
|
27
35
|
client = Google::APIClient.new
|
28
36
|
setup_credentials(client, authorization_code)
|
@@ -38,10 +46,10 @@ module GoogleAuthenticationBridge
|
|
38
46
|
end
|
39
47
|
|
40
48
|
def load_token_from_file
|
41
|
-
raise FileNotFoundError.new(@token_file) unless
|
49
|
+
raise FileNotFoundError.new(@token_file) unless token_file_exists?
|
42
50
|
|
43
51
|
begin
|
44
|
-
token_data =
|
52
|
+
token_data = GoogleAuthentication.load_file(@token_file)
|
45
53
|
token_data[:refresh_token] or raise
|
46
54
|
rescue
|
47
55
|
raise InvalidFileFormatError.new(@token_file)
|
@@ -74,7 +82,7 @@ module GoogleAuthenticationBridge
|
|
74
82
|
end
|
75
83
|
|
76
84
|
def refresh_tokens(client)
|
77
|
-
if
|
85
|
+
if token_file_exists?
|
78
86
|
client.authorization.update_token!(refresh_token: load_token_from_file)
|
79
87
|
tokens = client.authorization.fetch_access_token
|
80
88
|
else
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: google_auth_bridge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- GOV.UK Dev
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-12-31 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: oauth2
|
@@ -122,7 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
122
122
|
requirements:
|
123
123
|
- - ">="
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
hash:
|
125
|
+
hash: -3681856484147130035
|
126
126
|
segments:
|
127
127
|
- 0
|
128
128
|
version: "0"
|
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
131
|
requirements:
|
132
132
|
- - ">="
|
133
133
|
- !ruby/object:Gem::Version
|
134
|
-
hash:
|
134
|
+
hash: -3681856484147130035
|
135
135
|
segments:
|
136
136
|
- 0
|
137
137
|
version: "0"
|