oauth2_token 0.1.3 → 0.1.4
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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/oauth2_token.rb +20 -5
- data/lib/oauth2_token/version.rb +1 -1
- data/oauth2_token.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 421ec95d0448ebaba9477495d82c38271fae0c3e
|
4
|
+
data.tar.gz: a683c9bb9f62d1f1cd69db595c47af0728b3f4f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b82b103134d2e549ef3db4becfa6c275639b029e9faa4da47e9c0629ec625231faab460ec185d907a6ec84b306cb076ef112201533a323d30a2295380a4173a
|
7
|
+
data.tar.gz: 934478c6496b45314879e1b16bb246790ba6a2e09a560ae676307ba594ed14ba9ffb722e5499fa7470b8afec1ea4b6040b3ba8e5492d25d230c4aa6b572f6056
|
data/README.md
CHANGED
@@ -23,7 +23,7 @@ Or install it yourself as:
|
|
23
23
|
__authenticate and validate__
|
24
24
|
|
25
25
|
# options object
|
26
|
-
opts = { "uri" => "https
|
26
|
+
opts = { "uri" => "https://<oauth2 provider url>", "realm" => "<your realm>", "scope" => "<comma separated list of scopes>" }
|
27
27
|
|
28
28
|
# generate a token
|
29
29
|
token = Oauth2Token.get_token('client_id','client_secret', opts)
|
data/lib/oauth2_token.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "oauth2_token/version"
|
2
2
|
require "httparty"
|
3
|
+
require "jwt"
|
3
4
|
|
4
5
|
module Oauth2Token
|
5
6
|
|
@@ -8,12 +9,13 @@ module Oauth2Token
|
|
8
9
|
def get_token(client_id, client_secret, options={})
|
9
10
|
begin
|
10
11
|
endpoint = get_endpoint(options['uri'], "create")
|
12
|
+
jwt = create_jwt(client_id, client_secret, endpoint, options['realm'])
|
11
13
|
body = {
|
12
|
-
"grant_type"
|
13
|
-
"scope"
|
14
|
-
"realm"
|
15
|
-
"
|
16
|
-
"
|
14
|
+
"grant_type" => "client_credentials",
|
15
|
+
"scope" => options['scope'],
|
16
|
+
"realm" => options['realm'],
|
17
|
+
"client_assertion_type" => "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
|
18
|
+
"client_assertion" => jwt
|
17
19
|
}
|
18
20
|
response = wrap(HTTParty.post(endpoint, http_options.merge(:body => body)))
|
19
21
|
response['access_token']
|
@@ -42,6 +44,19 @@ module Oauth2Token
|
|
42
44
|
|
43
45
|
private
|
44
46
|
|
47
|
+
def create_jwt(client_id, client_secret, endpoint, realm)
|
48
|
+
iat = Time.now.to_i
|
49
|
+
exp = iat+600
|
50
|
+
payload = {
|
51
|
+
:iss => client_id,
|
52
|
+
:sub => client_id,
|
53
|
+
:aud => endpoint + '?realm=' + realm,
|
54
|
+
:iat => iat,
|
55
|
+
:exp => exp
|
56
|
+
}
|
57
|
+
JWT.encode payload, client_secret, 'HS256'
|
58
|
+
end
|
59
|
+
|
45
60
|
def get_endpoint(uri, action)
|
46
61
|
case action
|
47
62
|
when "create"
|
data/lib/oauth2_token/version.rb
CHANGED
data/oauth2_token.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oauth2_token
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sandeep Malalur
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jwt
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|