jive-oauth_token 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/jive-oauth_token.gemspec +1 -0
- data/lib/generators/jive/oauth_token/templates/migration_0.1.0.rb +2 -0
- data/lib/jive/oauth_token.rb +7 -1
- data/lib/jive/oauth_token/add_on/class_methods.rb +13 -0
- data/lib/jive/oauth_token/class_methods.rb +2 -0
- data/lib/jive/oauth_token/instance_methods.rb +47 -0
- data/lib/jive/oauth_token/version.rb +1 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d320aeb657a6840fa9edebb56bb5f888d3fe12f0
|
4
|
+
data.tar.gz: fea289cac5c6a5aa5350304b00790c8df5a3c747
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 963c20cc924ee303214ebd625ce02497962d45bb655cdcba3a2a010c6cda4a528dbe383dd891ad592240416e4f2fc6f77813b6c74391386625da36a80c53a5e7
|
7
|
+
data.tar.gz: 2307ccbf1f6d123635b793b94cafe0ac62daf134efb191a8b3c39f7283bc1e687a9ae2f618d5a1bce0a411376e607548920c80ad88656886756fbb763dbbfc3e
|
data/jive-oauth_token.gemspec
CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.add_dependency "jive-add_on", ">= 0.0.2"
|
21
22
|
spec.add_dependency "activerecord", [">= 3.0", "< 5.0"]
|
22
23
|
|
23
24
|
if RUBY_PLATFORM == 'java'
|
data/lib/jive/oauth_token.rb
CHANGED
@@ -2,6 +2,9 @@ require "active_support"
|
|
2
2
|
require "active_support/dependencies"
|
3
3
|
require "active_record"
|
4
4
|
|
5
|
+
require "jive/add_on"
|
6
|
+
require "jive/oauth_token/add_on/class_methods"
|
7
|
+
|
5
8
|
require "jive/oauth_token/version"
|
6
9
|
require "jive/oauth_token/compatibility"
|
7
10
|
|
@@ -14,4 +17,7 @@ module Jive
|
|
14
17
|
end
|
15
18
|
|
16
19
|
Jive::OauthToken.send :include, Jive::OauthToken::InstanceMethods
|
17
|
-
Jive::OauthToken.send :extend, Jive::OauthToken::ClassMethods
|
20
|
+
Jive::OauthToken.send :extend, Jive::OauthToken::ClassMethods
|
21
|
+
|
22
|
+
# We want add-ons to know they can now associate with OAuthTokens
|
23
|
+
Jive::AddOn.send :include, Jive::OauthToken::AddOn::ClassMethods
|
@@ -4,6 +4,53 @@ module Jive
|
|
4
4
|
def self.included(base)
|
5
5
|
base.table_name = "jive_oauth_tokens"
|
6
6
|
end
|
7
|
+
|
8
|
+
# Gets a valid access token from this object - Will refresh existing token if invalid
|
9
|
+
def valid_access_token
|
10
|
+
# The token we have stored is expired - fetch a new one using the refresh token
|
11
|
+
self.refresh_access_token if self.access_token_expired?
|
12
|
+
|
13
|
+
self.access_token
|
14
|
+
end
|
15
|
+
|
16
|
+
# Fetches a refreshed access token
|
17
|
+
def refresh_access_token
|
18
|
+
require "open-uri"
|
19
|
+
require "net/http"
|
20
|
+
require "openssl"
|
21
|
+
require "base64"
|
22
|
+
|
23
|
+
uri = URI.parse("#{self.add_on.jive_url}/oauth2/token")
|
24
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
25
|
+
http.use_ssl = true
|
26
|
+
|
27
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
28
|
+
request.basic_auth self.add_on.client_id, self.add_on.client_secret
|
29
|
+
request.set_form_data({
|
30
|
+
"refresh_token" => "#{self.refresh_token}",
|
31
|
+
"grant_type" => "refresh_token",
|
32
|
+
})
|
33
|
+
|
34
|
+
response = http.request(request)
|
35
|
+
json_body = JSON.parse(response.body)
|
36
|
+
|
37
|
+
if (response.code.to_i != 200)
|
38
|
+
raise RuntimeError, json_body["error"].to_s.upcase
|
39
|
+
end
|
40
|
+
|
41
|
+
self.access_token = json_body["access_token"]
|
42
|
+
self.expires_in = json_body["expires_in"]
|
43
|
+
self.expires_at = json_body["expires_in"].to_i.seconds.from_now
|
44
|
+
self.save
|
45
|
+
end
|
46
|
+
|
47
|
+
# Return whether access token is expired
|
48
|
+
def access_token_expired?
|
49
|
+
return false if self.expires_at.nil?
|
50
|
+
|
51
|
+
# Expiration date less than now == expired
|
52
|
+
self.expires_at < Time.now
|
53
|
+
end
|
7
54
|
end
|
8
55
|
end
|
9
56
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jive-oauth_token
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Butch Marshall
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jive-add_on
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.2
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: activerecord
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,6 +164,7 @@ files:
|
|
150
164
|
- lib/generators/jive/oauth_token/oauth_token_generator.rb
|
151
165
|
- lib/generators/jive/oauth_token/templates/migration_0.1.0.rb
|
152
166
|
- lib/jive/oauth_token.rb
|
167
|
+
- lib/jive/oauth_token/add_on/class_methods.rb
|
153
168
|
- lib/jive/oauth_token/class_methods.rb
|
154
169
|
- lib/jive/oauth_token/compatibility.rb
|
155
170
|
- lib/jive/oauth_token/instance_methods.rb
|