monk-id 1.0.0 → 1.1.0
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 +15 -0
- data/README.md +159 -10
- data/lib/monk/id.rb +39 -13
- data/lib/monk/id/version.rb +1 -1
- data/monk-id.gemspec +8 -6
- metadata +47 -27
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZWZiMDQ3ZjBlYWFiNzAxMWY3ZTdiZGY0NzJhNTg4ODE2YmQwNTViNg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YjNkN2EwMTFjZWZkNmRmMmY2MDdlMzllNDA1ODg4YTJiYzE4ZTM3Nw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OWQ3YmU5MDgyZjUzOTdmYjkzYTY4NTgyOTRmMjJkOTYxNWJhMzAwZDJhM2Ex
|
10
|
+
NjhmMDVmMWE0ODA4ZGE4MDM4ZTkwZDEwY2UyMjdlYWVkYjRmYWQ4M2VhYjIz
|
11
|
+
N2JlM2QxZTJmZjliNDgzMzBiMGY2YjYyOWI0ZmRhOTgzYzZlMTE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YWI3MWQyYTg5Zjk2MTcyNzZhZmM1NmU2ZTBiYzE0NTY0NzZhNGE4MDcxNjMx
|
14
|
+
ZmUxYzAyZjA0ZTJhZjU0NWRjNmRlMGVkNmYyNjY3NGU5Y2JmMDJmMDc2Y2E1
|
15
|
+
NzAwZmYwYjk4Y2E1ODI1MmM5ODdlZDBkNTRlMzk5MzY5ZDQwNjE=
|
data/README.md
CHANGED
@@ -1,35 +1,86 @@
|
|
1
1
|
Monk ID Ruby
|
2
2
|
============
|
3
3
|
|
4
|
-
|
4
|
+
[](http://badge.fury.io/rb/monk-id)
|
5
5
|
|
6
|
-
|
6
|
+
Integrate Monk ID authentication and single sign-on for apps and websites on the
|
7
|
+
server-side.
|
8
|
+
|
9
|
+
* [Documentation](http://monkdev.github.io/monk-id-ruby/Monk/Id.html)
|
10
|
+
|
11
|
+
Overview
|
12
|
+
--------
|
13
|
+
|
14
|
+
Monk ID authentication and single sign-on works in the browser by integrating
|
15
|
+
[Monk ID JS](https://github.com/MonkDev/monk-id-js). Only being able to check
|
16
|
+
whether a user is signed in on the client-side is limiting, however, which is
|
17
|
+
where this library is helpful. It takes a payload from the client-side
|
18
|
+
JavaScript and decodes it for access in your Ruby code. There is no Monk ID API
|
19
|
+
that can be accessed on the server-side, so this library depends on client-side
|
20
|
+
integration.
|
21
|
+
|
22
|
+
### Install
|
23
|
+
|
24
|
+
Add the gem to your `Gemfile` if using [Bundler](http://bundler.io):
|
7
25
|
|
8
26
|
```ruby
|
9
|
-
gem 'monk-id'
|
27
|
+
gem 'monk-id'
|
10
28
|
```
|
11
29
|
|
12
|
-
|
13
|
-
|
14
|
-
|
30
|
+
```bash
|
31
|
+
$ bundle
|
32
|
+
```
|
33
|
+
|
34
|
+
Or install manually:
|
35
|
+
|
36
|
+
```bash
|
37
|
+
$ gem install monk-id
|
38
|
+
```
|
39
|
+
|
40
|
+
### Configure
|
41
|
+
|
42
|
+
Configuration is done in an external YAML file. There's a sample file in this
|
43
|
+
repository: `config/monk_id.sample.yml`.
|
44
|
+
|
45
|
+
Rails and Sinatra apps need only copy this file to `config/monk_id.yml` for it
|
46
|
+
to be loaded automatically.
|
47
|
+
|
48
|
+
All other apps need to load the file explicitly:
|
15
49
|
|
16
50
|
```ruby
|
17
51
|
Monk::Id.load_config('/path/to/monk_id.yml', 'development')
|
18
52
|
```
|
19
53
|
|
20
|
-
|
54
|
+
Remember, replace the sample values with your own, and keep the file safe as it
|
55
|
+
contains your app secret.
|
56
|
+
|
57
|
+
### Access
|
58
|
+
|
59
|
+
If you have Monk ID JS configured to store the payload automatically in a cookie
|
60
|
+
(the default), simply pass a hash-like cookies object to load the payload from:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
Monk::Id.load_payload(cookies)
|
64
|
+
```
|
65
|
+
|
66
|
+
The encoded payload can also be passed directly, which is useful if you're
|
67
|
+
sending it in a GET/POST request instead:
|
21
68
|
|
22
69
|
```ruby
|
23
70
|
Monk::Id.load_payload(params[:monk_id_payload])
|
24
71
|
```
|
25
72
|
|
26
|
-
|
73
|
+
Loading the payload must be done before trying to access any values stored in
|
74
|
+
the payload. In Rails, this usually means placing it in a `before_action` in
|
75
|
+
your `ApplicationController`.
|
76
|
+
|
77
|
+
Once the payload is loaded, you can ask whether the user is signed in:
|
27
78
|
|
28
79
|
```ruby
|
29
|
-
Monk::Id.
|
80
|
+
Monk::Id.signed_in?
|
30
81
|
```
|
31
82
|
|
32
|
-
|
83
|
+
Or for their ID and email:
|
33
84
|
|
34
85
|
```ruby
|
35
86
|
Monk::Id.user_id
|
@@ -38,3 +89,101 @@ Monk::Id.user_email
|
|
38
89
|
|
39
90
|
`nil` is returned if the user isn't signed in or the payload can't be decoded
|
40
91
|
and verified.
|
92
|
+
|
93
|
+
Development
|
94
|
+
-----------
|
95
|
+
|
96
|
+
Start by installing the development dependencies with Bundler:
|
97
|
+
|
98
|
+
```bash
|
99
|
+
$ bundle
|
100
|
+
```
|
101
|
+
|
102
|
+
This requires all subsequent commands be prepended with `bundle exec`, which has
|
103
|
+
been ommitted for conciseness.
|
104
|
+
|
105
|
+
During development, changes must be tested manually since an automated test
|
106
|
+
suite does not yet exist. This is best done by requiring the library locally in
|
107
|
+
an app or website that integrates it already. There are a few ways to do this.
|
108
|
+
|
109
|
+
### With Bundler
|
110
|
+
|
111
|
+
Not to be confused with the fact that Bundler is used for development of this
|
112
|
+
library, if Bundler is used in the test app or website, you can either specify a
|
113
|
+
path to the library locally:
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
gem 'monk-id', :path => '/path/to/monk-id-ruby'
|
117
|
+
```
|
118
|
+
|
119
|
+
Or configure Bundler to use a local repository instead of the GitHub repository
|
120
|
+
(more details [in the documentation](http://bundler.io/v1.5/git.html#local)):
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
gem 'monk-id', :github => 'MonkDev/monk-id-ruby', :branch => 'master'
|
124
|
+
```
|
125
|
+
|
126
|
+
```bash
|
127
|
+
$ bundle config local.monk-id /path/to/monk-id-ruby
|
128
|
+
```
|
129
|
+
|
130
|
+
### Without Bundler
|
131
|
+
|
132
|
+
If Bundler is not used, you can either build and install the gem as a system
|
133
|
+
gem (this must be done for every change):
|
134
|
+
|
135
|
+
```bash
|
136
|
+
$ rake install
|
137
|
+
```
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
require 'monk/id'
|
141
|
+
```
|
142
|
+
|
143
|
+
Or require the library directly:
|
144
|
+
|
145
|
+
```ruby
|
146
|
+
require '/path/to/monk-id-ruby/lib/monk/id'
|
147
|
+
```
|
148
|
+
|
149
|
+
### Documentation
|
150
|
+
|
151
|
+
[YARD](http://yardoc.org) is used for code documentation. During development,
|
152
|
+
you can preview as you document by starting the YARD server:
|
153
|
+
|
154
|
+
```bash
|
155
|
+
$ yard server --reload
|
156
|
+
```
|
157
|
+
|
158
|
+
This hosts the documentation at http://localhost:8808 and automatically watches
|
159
|
+
for changes on page refresh.
|
160
|
+
|
161
|
+
The documentation can also be built to a `doc` directory (that is ignored by
|
162
|
+
git):
|
163
|
+
|
164
|
+
```bash
|
165
|
+
$ yard
|
166
|
+
```
|
167
|
+
|
168
|
+
Deployment
|
169
|
+
----------
|
170
|
+
|
171
|
+
[gem-release](https://github.com/svenfuchs/gem-release) is used to
|
172
|
+
|
173
|
+
1. bump the version in `lib/monk/id/version.rb`,
|
174
|
+
2. tag and push the release to GitHub,
|
175
|
+
3. and release to [RubyGems](https://rubygems.org).
|
176
|
+
|
177
|
+
These steps can be executed individually, but it's easiest to do all at once:
|
178
|
+
|
179
|
+
```bash
|
180
|
+
$ gem bump --version major|minor|patch --tag --release
|
181
|
+
```
|
182
|
+
|
183
|
+
Be sure to choose the correct version by following
|
184
|
+
[Semantic Versioning](http://semver.org).
|
185
|
+
|
186
|
+
### Publish Documentation
|
187
|
+
|
188
|
+
After releasing a new version, the documentation must be manually built and
|
189
|
+
published to the `gh-pages` branch.
|
data/lib/monk/id.rb
CHANGED
@@ -3,6 +3,8 @@ require 'json'
|
|
3
3
|
require 'openssl'
|
4
4
|
require 'yaml'
|
5
5
|
|
6
|
+
require 'monk/id/version'
|
7
|
+
|
6
8
|
# Global Monk namespace.
|
7
9
|
module Monk
|
8
10
|
# Integrate Monk ID on the server-side by accessing payloads from the
|
@@ -23,23 +25,16 @@ module Monk
|
|
23
25
|
# {CONFIG_FILE}, as it's loaded automatically.
|
24
26
|
#
|
25
27
|
# @param path [String] Path of YAML config file to load. Leave `nil` to
|
26
|
-
# read from environment
|
28
|
+
# read from environment (`MONK_ID_CONFIG` variable, Rails,
|
29
|
+
# Sinatra).
|
27
30
|
# @param environment [String] Environment section to use. Leave `nil` to
|
28
|
-
# read from environment
|
29
|
-
# `development`.
|
31
|
+
# read from environment (`MONK_ID_ENV` variable, Rails, Sinatra).
|
32
|
+
# Defaults to `development`.
|
30
33
|
# @raise [StandardError] If the file doesn't exist or can't be read.
|
31
34
|
# @return [Hash<String>] Loaded config values.
|
32
35
|
def load_config(path = nil, environment = nil)
|
33
|
-
|
34
|
-
|
35
|
-
environment ||= Rails.env
|
36
|
-
elsif defined? Sinatra
|
37
|
-
path ||= File.join(Sinatra::Application.settings.root, CONFIG_FILE)
|
38
|
-
environment ||= Sinatra::Application.settings.environment.to_s
|
39
|
-
else
|
40
|
-
path ||= ENV['MONK_ID_CONFIG']
|
41
|
-
environment ||= ENV['MONK_ID_ENV'] || 'development'
|
42
|
-
end
|
36
|
+
path ||= config_path_from_environment
|
37
|
+
environment ||= config_environment
|
43
38
|
|
44
39
|
config = YAML.load_file(path)[environment]
|
45
40
|
|
@@ -116,6 +111,37 @@ module Monk
|
|
116
111
|
# Loaded payload.
|
117
112
|
@@payload = nil
|
118
113
|
|
114
|
+
# Get the path to the config file from the environment. Supports `ENV`
|
115
|
+
# variable, Rails, and Sinatra.
|
116
|
+
#
|
117
|
+
# @return [String] Path to the config file.
|
118
|
+
# @return [nil] If not set by the environment.
|
119
|
+
def config_path_from_environment
|
120
|
+
if ENV['MONK_ID_CONFIG']
|
121
|
+
ENV['MONK_ID_CONFIG']
|
122
|
+
elsif defined? Rails
|
123
|
+
File.join(Rails.root, CONFIG_FILE)
|
124
|
+
elsif defined? Sinatra
|
125
|
+
File.join(Sinatra::Application.settings.root, CONFIG_FILE)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
# Get the environment to load within the config. Supports `ENV` variable,
|
130
|
+
# Rails, and Sinatra. Defaults to `development` if none specify.
|
131
|
+
#
|
132
|
+
# @return [String] Environment name.
|
133
|
+
def config_environment
|
134
|
+
if ENV['MONK_ID_ENV']
|
135
|
+
ENV['MONK_ID_ENV']
|
136
|
+
elsif defined? Rails
|
137
|
+
Rails.env
|
138
|
+
elsif defined? Sinatra
|
139
|
+
Sinatra::Application.settings.environment.to_s
|
140
|
+
else
|
141
|
+
'development'
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
119
145
|
# Verify that a config has all the required values.
|
120
146
|
#
|
121
147
|
# @param config [Hash<String>] Config values.
|
data/lib/monk/id/version.rb
CHANGED
data/monk-id.gemspec
CHANGED
@@ -8,17 +8,19 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Monk::Id::VERSION.dup
|
9
9
|
spec.authors = ['Monk Development, Inc.']
|
10
10
|
spec.email = ['support@monkdevelopment.com']
|
11
|
-
spec.
|
12
|
-
spec.
|
11
|
+
spec.summary = 'Integrate Monk ID authentication and single sign-on for apps and websites on the server-side.'
|
12
|
+
spec.description = spec.summary
|
13
13
|
spec.homepage = 'https://github.com/MonkDev/monk-id-ruby'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
16
|
-
spec.files = `git ls-files`.split(
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_development_dependency 'bundler', '~> 1.
|
22
|
-
spec.add_development_dependency '
|
23
|
-
spec.add_development_dependency '
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.5'
|
22
|
+
spec.add_development_dependency 'gem-release', '~> 0.7'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.1'
|
24
|
+
spec.add_development_dependency 'yard', '~> 0.8'
|
25
|
+
spec.add_development_dependency 'redcarpet', '~> 3.1'
|
24
26
|
end
|
metadata
CHANGED
@@ -1,66 +1,87 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: monk-id
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
5
|
-
prerelease:
|
4
|
+
version: 1.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Monk Development, Inc.
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-
|
11
|
+
date: 2014-03-25 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: '1.
|
19
|
+
version: '1.5'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: '1.
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: gem-release
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.7'
|
30
41
|
- !ruby/object:Gem::Dependency
|
31
42
|
name: rake
|
32
43
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
44
|
requirements:
|
35
|
-
- -
|
45
|
+
- - ~>
|
36
46
|
- !ruby/object:Gem::Version
|
37
|
-
version: '
|
47
|
+
version: '10.1'
|
38
48
|
type: :development
|
39
49
|
prerelease: false
|
40
50
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
51
|
requirements:
|
43
|
-
- -
|
52
|
+
- - ~>
|
44
53
|
- !ruby/object:Gem::Version
|
45
|
-
version: '
|
54
|
+
version: '10.1'
|
46
55
|
- !ruby/object:Gem::Dependency
|
47
56
|
name: yard
|
48
57
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
58
|
requirements:
|
51
|
-
- -
|
59
|
+
- - ~>
|
52
60
|
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
61
|
+
version: '0.8'
|
54
62
|
type: :development
|
55
63
|
prerelease: false
|
56
64
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
65
|
requirements:
|
59
|
-
- -
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.8'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: redcarpet
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.1'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
60
81
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
62
|
-
description: Integrate Monk ID
|
63
|
-
|
82
|
+
version: '3.1'
|
83
|
+
description: Integrate Monk ID authentication and single sign-on for apps and websites
|
84
|
+
on the server-side.
|
64
85
|
email:
|
65
86
|
- support@monkdevelopment.com
|
66
87
|
executables: []
|
@@ -79,28 +100,27 @@ files:
|
|
79
100
|
homepage: https://github.com/MonkDev/monk-id-ruby
|
80
101
|
licenses:
|
81
102
|
- MIT
|
103
|
+
metadata: {}
|
82
104
|
post_install_message:
|
83
105
|
rdoc_options: []
|
84
106
|
require_paths:
|
85
107
|
- lib
|
86
108
|
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
-
none: false
|
88
109
|
requirements:
|
89
110
|
- - ! '>='
|
90
111
|
- !ruby/object:Gem::Version
|
91
112
|
version: '0'
|
92
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
-
none: false
|
94
114
|
requirements:
|
95
115
|
- - ! '>='
|
96
116
|
- !ruby/object:Gem::Version
|
97
117
|
version: '0'
|
98
118
|
requirements: []
|
99
119
|
rubyforge_project:
|
100
|
-
rubygems_version:
|
120
|
+
rubygems_version: 2.2.2
|
101
121
|
signing_key:
|
102
|
-
specification_version:
|
103
|
-
summary: Integrate Monk ID
|
104
|
-
|
122
|
+
specification_version: 4
|
123
|
+
summary: Integrate Monk ID authentication and single sign-on for apps and websites
|
124
|
+
on the server-side.
|
105
125
|
test_files: []
|
106
126
|
has_rdoc:
|