layer-identity_token 0.0.1
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 +7 -0
- data/.gitignore +2 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +71 -0
- data/Rakefile +1 -0
- data/layer-identity_token.gemspec +26 -0
- data/lib/layer.rb +5 -0
- data/lib/layer/identity_token.rb +70 -0
- data/lib/layer/identity_token/version.rb +5 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3dca795400df6fa9fb3f766405135f118fc28b57
|
4
|
+
data.tar.gz: 93cfdf4231d91ecdcd98a3e93a5860878ba2bae5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9a854de5337a6d2701e3ae24bcafe37c08189354d9a3ca3be7ff1121c2568c4c25029e179e3afc0036e03b33c6f4d7e23896f69c1f133a0c3b1065f8ce14b584
|
7
|
+
data.tar.gz: a4b53d82dd69ced9099bd733c03b489e4f89d3c4d297dd524bff1464c277c4158a82a18e7abab4aadef27e2d79dda8842d65c292210175f04c61218b30b2605c
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 dreimannzelt
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# Layer::IdentityToken
|
2
|
+
|
3
|
+
Use this class to generate a token for authenticating the Layer SDK
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'layer_identity_token'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install layer_identity_token
|
18
|
+
|
19
|
+
## Setup
|
20
|
+
|
21
|
+
1. Create a layer app
|
22
|
+
2. Write down your `provider ID` (app's info tab)
|
23
|
+
3. Create a new private key (app's authentication tab – _we recommend to create keys for each developer and/or environments like: staging, development_)
|
24
|
+
4. Save the `private key` and note the `key ID`
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
token = Layer::IdentityToken.new(user_id, nonce, optional_expires_at)
|
30
|
+
token.encode
|
31
|
+
```
|
32
|
+
|
33
|
+
### Integration
|
34
|
+
|
35
|
+
If you want to return this token as JSON and your framework (like Rails) uses `#as_json` you just write a controller like:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
class ApiController
|
39
|
+
def hello_layer
|
40
|
+
token = Layer::IdentityToken.new(current_user.id, params[:nonce])
|
41
|
+
|
42
|
+
render json: token
|
43
|
+
end
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
## Configuration
|
48
|
+
|
49
|
+
Per default the class looks for ENV variables like:
|
50
|
+
|
51
|
+
```
|
52
|
+
LAYER_PROVIDER_ID
|
53
|
+
LAYER_KEY_ID
|
54
|
+
LAYER_PRIVATE_KEY
|
55
|
+
```
|
56
|
+
|
57
|
+
If you can not set ENV variables you can also set them on the class directly:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
Layer::IdentityToken.layer_provider_id = "provider_id"
|
61
|
+
Layer::IdentityToken.layer_key_id = "key_id"
|
62
|
+
Layer::IdentityToken.layer_private_key = "private_key"
|
63
|
+
```
|
64
|
+
|
65
|
+
## Contributing
|
66
|
+
|
67
|
+
1. Fork it
|
68
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
69
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
70
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
71
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'layer/identity_token/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "layer-identity_token"
|
8
|
+
spec.version = Layer::IdentityToken::VERSION
|
9
|
+
spec.authors = ['we5']
|
10
|
+
spec.email = ['bjoern@we5.de']
|
11
|
+
spec.description = %q{Simple class for creating an IdentityToken and authenticating Layer clients}
|
12
|
+
spec.summary = %q{IdentityToken for Layer clients}
|
13
|
+
spec.homepage = 'http://github.com/dreimannzelt/layer-identity_token'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
22
|
+
spec.add_development_dependency 'rake', '~> 0'
|
23
|
+
spec.add_development_dependency 'pry', '~> 0'
|
24
|
+
|
25
|
+
spec.add_dependency 'jwt', '~> 1.4', '>= 1.4.1'
|
26
|
+
end
|
data/lib/layer.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require "jwt"
|
2
|
+
|
3
|
+
module Layer
|
4
|
+
class IdentityToken
|
5
|
+
VERSION = "0.0.1"
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_writer :layer_provider_id,
|
9
|
+
:layer_key_id,
|
10
|
+
:layer_private_key
|
11
|
+
|
12
|
+
def layer_provider_id
|
13
|
+
@layer_provider_id || ENV["LAYER_PROVIDER_ID"]
|
14
|
+
end
|
15
|
+
|
16
|
+
def layer_key_id
|
17
|
+
@layer_key_id || ENV["LAYER_KEY_ID"]
|
18
|
+
end
|
19
|
+
|
20
|
+
def layer_private_key
|
21
|
+
@layer_private_key || ENV["LAYER_PRIVATE_KEY"]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_reader :user_id,
|
26
|
+
:nonce,
|
27
|
+
:expires_at
|
28
|
+
|
29
|
+
def initialize(user_id, nonce, expires_at = (Time.now+(86400*14)))
|
30
|
+
@user_id = user_id
|
31
|
+
@nonce = nonce
|
32
|
+
@expires_at = expires_at
|
33
|
+
end
|
34
|
+
|
35
|
+
def encode
|
36
|
+
JWT.encode(claim, private_key, "RS256", headers)
|
37
|
+
end
|
38
|
+
|
39
|
+
def as_json(options = {})
|
40
|
+
encode
|
41
|
+
end
|
42
|
+
|
43
|
+
alias_method :to_s, :encode
|
44
|
+
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def headers
|
49
|
+
{
|
50
|
+
typ: "JWS",
|
51
|
+
cty: "layer-eit;v=1",
|
52
|
+
kid: self.class.layer_key_id
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def claim
|
57
|
+
{
|
58
|
+
iss: self.class.layer_provider_id,
|
59
|
+
prn: user_id.to_s,
|
60
|
+
iat: Time.now.to_i,
|
61
|
+
exp: expires_at.to_i,
|
62
|
+
nce: nonce
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
def private_key
|
67
|
+
OpenSSL::PKey::RSA.new(self.class.layer_private_key)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: layer-identity_token
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- we5
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: jwt
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.4'
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 1.4.1
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '1.4'
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 1.4.1
|
75
|
+
description: Simple class for creating an IdentityToken and authenticating Layer clients
|
76
|
+
email:
|
77
|
+
- bjoern@we5.de
|
78
|
+
executables: []
|
79
|
+
extensions: []
|
80
|
+
extra_rdoc_files: []
|
81
|
+
files:
|
82
|
+
- ".gitignore"
|
83
|
+
- Gemfile
|
84
|
+
- LICENSE.txt
|
85
|
+
- README.md
|
86
|
+
- Rakefile
|
87
|
+
- layer-identity_token.gemspec
|
88
|
+
- lib/layer.rb
|
89
|
+
- lib/layer/identity_token.rb
|
90
|
+
- lib/layer/identity_token/version.rb
|
91
|
+
homepage: http://github.com/dreimannzelt/layer-identity_token
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.4.3
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: IdentityToken for Layer clients
|
115
|
+
test_files: []
|