cow_auth 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.travis.yml +3 -2
- data/CODE_OF_CONDUCT.md +54 -29
- data/Gemfile +2 -0
- data/Gemfile.lock +29 -0
- data/LICENSE.txt +1 -1
- data/README.md +38 -30
- data/Rakefile +1 -1
- data/bin/console +5 -5
- data/cow_auth.gemspec +9 -7
- data/lib/cow_auth/user.rb +2 -0
- data/lib/cow_auth/version.rb +1 -1
- metadata +10 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a2ee818192fd63ac1695e4d7ed5f41b10fe4039ad7b76b1e2cc409dc4fec11e
|
4
|
+
data.tar.gz: af99e43d6425225b8f4a3afae7033091335054e505c748ba167392110b8d556a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0729a56a18c44e6d8210f5837f710df3c61027a4c1497252553d5c869aaf776dc368cb33dd5f3f0c0215680788f0e32bb9f9cf5767293762050d3e43f09b60eb'
|
7
|
+
data.tar.gz: 180fdbd0e2df6bcd2c245c3474bb83a28f4c72463c40d2c21ad4ba4e6a8deb1c1963503a3c3194326b8139347c3936613e7099e2a5e15431d08649f1d09d1096
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CODE_OF_CONDUCT.md
CHANGED
@@ -1,24 +1,41 @@
|
|
1
|
-
# Contributor Code of Conduct
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
2
|
|
3
|
-
|
4
|
-
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
-
contribute through reporting issues, posting feature requests, updating
|
6
|
-
documentation, submitting pull requests or patches, and other activities.
|
3
|
+
## Our Pledge
|
7
4
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
12
22
|
|
13
23
|
Examples of unacceptable behavior by participants include:
|
14
24
|
|
15
|
-
* The use of sexualized language or imagery
|
16
|
-
|
17
|
-
* Trolling
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
18
28
|
* Public or private harassment
|
19
|
-
* Publishing
|
20
|
-
|
21
|
-
* Other
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
22
39
|
|
23
40
|
Project maintainers have the right and responsibility to remove, edit, or
|
24
41
|
reject comments, commits, code, wiki edits, issues, and other contributions
|
@@ -26,24 +43,32 @@ that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
26
43
|
permanently any contributor for other behaviors that they deem inappropriate,
|
27
44
|
threatening, offensive, or harmful.
|
28
45
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
33
54
|
|
34
|
-
|
35
|
-
when an individual is representing the project or its community.
|
55
|
+
## Enforcement
|
36
56
|
|
37
57
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
-
reported by contacting
|
58
|
+
reported by contacting the project team at mickey@vt.edu. All
|
39
59
|
complaints will be reviewed and investigated and will result in a response that
|
40
|
-
is deemed necessary and appropriate to the circumstances.
|
41
|
-
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
-
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
43
69
|
|
44
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
-
|
46
|
-
[http://contributor-covenant.org/version/1/3/0/][version]
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
47
72
|
|
48
73
|
[homepage]: http://contributor-covenant.org
|
49
|
-
[version]: http://contributor-covenant.org/version/1/
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
cow_auth (0.5.1)
|
5
|
+
scrypt (~> 3.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ffi (1.9.18)
|
11
|
+
ffi-compiler (1.0.1)
|
12
|
+
ffi (>= 1.0.0)
|
13
|
+
rake
|
14
|
+
minitest (5.10.3)
|
15
|
+
rake (10.5.0)
|
16
|
+
scrypt (3.0.5)
|
17
|
+
ffi-compiler (>= 1.0, < 2.0)
|
18
|
+
|
19
|
+
PLATFORMS
|
20
|
+
ruby
|
21
|
+
|
22
|
+
DEPENDENCIES
|
23
|
+
bundler (~> 1.16)
|
24
|
+
cow_auth!
|
25
|
+
minitest (~> 5.0)
|
26
|
+
rake (~> 10.0)
|
27
|
+
|
28
|
+
BUNDLED WITH
|
29
|
+
1.16.1.pre1
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -18,13 +18,17 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
$ gem install cow_auth
|
20
20
|
|
21
|
-
##
|
21
|
+
## Usage
|
22
22
|
|
23
|
-
###
|
23
|
+
### Model
|
24
|
+
|
25
|
+
Configure your user model to add the authentication mechanism.
|
26
|
+
|
27
|
+
#### Generator (Example)
|
24
28
|
|
25
29
|
$ bundle exec rails generate model user uuid:string:uniq email:string:uniq sid:string:uniq encrypted_password:string locale:string first_name:string last_name:string role:integer sign_in_count:integer is_approved:boolean is_deleted:boolean
|
26
30
|
|
27
|
-
|
31
|
+
#### Migration (Example)
|
28
32
|
|
29
33
|
# Modified migration; includes indexes and other stuff you might not want.
|
30
34
|
class CreateUsers < ActiveRecord::Migration[5.2]
|
@@ -49,46 +53,34 @@ Or install it yourself as:
|
|
49
53
|
end
|
50
54
|
end
|
51
55
|
|
52
|
-
|
56
|
+
#### Model Concern
|
53
57
|
|
54
58
|
class User < ApplicationRecord
|
55
59
|
include CowAuth::User
|
56
60
|
end
|
57
61
|
|
58
|
-
|
59
|
-
|
60
|
-
User.create! email: 'email', password: 'password'
|
61
|
-
|
62
|
-
## Token Authentication
|
63
|
-
|
64
|
-
### Authenticate (Example)
|
65
|
-
|
66
|
-
curl -X POST -i --data-urlencode email=user@domain.tld --data-urlencode password=password https://api.domain.tld/v1/sessions
|
67
|
-
|
68
|
-
curl -X DELETE -i https://api.domain.tld/v1/sessions -H "Authorization: Token token=b5503c9b85b881f8b3ddbd82f511912cb5503c9b85b881f8b3ddbd82f511912c,sid=C3281846f3976809796f91cf6bbb35c53"
|
69
|
-
|
70
|
-
### Authenticated Request
|
62
|
+
#### Create User
|
71
63
|
|
72
|
-
|
64
|
+
User.create! email: 'user@domain.tld', password: 'password'
|
73
65
|
|
74
|
-
|
66
|
+
### Controllers
|
75
67
|
|
76
|
-
|
68
|
+
Configure the appropriate controllers to require authentication.
|
77
69
|
|
78
|
-
|
70
|
+
#### Controller Concern
|
79
71
|
|
80
72
|
Add the following lines in the controller(s) that you want to enforce authentication for.
|
81
73
|
|
82
74
|
include CowAuth::TokenAuth::AuthenticateRequest
|
83
75
|
before_action :authenticate_user
|
84
76
|
|
85
|
-
Add the following private method to the ApplicationController (assuming User is the
|
77
|
+
Add the following private method to the ApplicationController (assuming User is the model doing the authentication) to define the authentication class for the controller concern.
|
86
78
|
|
87
79
|
def authentication_class
|
88
80
|
return User
|
89
81
|
end
|
90
82
|
|
91
|
-
|
83
|
+
#### Application Controller Example
|
92
84
|
|
93
85
|
class ApplicationController < ActionController::API
|
94
86
|
include CowAuth::TokenAuth::AuthenticateRequest
|
@@ -108,7 +100,7 @@ Add the following private method to the ApplicationController (assuming User is
|
|
108
100
|
end
|
109
101
|
end
|
110
102
|
|
111
|
-
|
103
|
+
#### Sessions Controller Example
|
112
104
|
|
113
105
|
class Api::V1::SessionsController < ApplicationController
|
114
106
|
include CowAuth::TokenAuth::SessionEndpoints
|
@@ -116,26 +108,42 @@ Add the following private method to the ApplicationController (assuming User is
|
|
116
108
|
skip_before_action :authenticate_user, only: [:create]
|
117
109
|
end
|
118
110
|
|
111
|
+
### Token Authentication
|
112
|
+
|
113
|
+
#### Authenticate (Example)
|
114
|
+
|
115
|
+
curl -X POST -i --data-urlencode email=user@domain.tld --data-urlencode password=password https://api.domain.tld/v1/sessions
|
116
|
+
|
117
|
+
curl -X DELETE -i https://api.domain.tld/v1/sessions -H "Authorization: Token token=b5503c9b85b881f8b3ddbd82f511912cb5503c9b85b881f8b3ddbd82f511912c,sid=C3281846f3976809796f91cf6bbb35c53"
|
118
|
+
|
119
|
+
#### Authenticated Request
|
120
|
+
|
121
|
+
Note that "token" and "sid" are both required.
|
122
|
+
|
123
|
+
Example GET:
|
124
|
+
|
125
|
+
curl -X GET -i https://api.domain.tld/v1/test -H "Authorization: Token token=b5503c9b85b881f8b3ddbd82f511912cb5503c9b85b881f8b3ddbd82f511912c,sid=C3281846f3976809796f91cf6bbb35c53"
|
126
|
+
|
119
127
|
## Development
|
120
128
|
|
121
129
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
122
130
|
|
123
131
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
124
132
|
|
125
|
-
bundle exec gem build cow_auth.gemspec
|
126
|
-
bundle exec gem install cow_auth-0.1.0.gem
|
127
|
-
|
128
133
|
### Notes
|
129
134
|
|
130
135
|
cow_auth> bundle exec gem build cow_auth.gemspec
|
131
|
-
|
136
|
+
cow_auth> bundle exec gem install cow_auth-0.1.0.gem
|
132
137
|
app> bundle
|
133
138
|
|
134
139
|
## Contributing
|
135
140
|
|
136
141
|
Bug reports and pull requests are welcome on GitHub at https://github.com/mickey13/cow_auth. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
137
142
|
|
138
|
-
|
139
143
|
## License
|
140
144
|
|
141
|
-
The gem is available as open source under the terms of the [MIT License](
|
145
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
146
|
+
|
147
|
+
## Code of Conduct
|
148
|
+
|
149
|
+
Everyone interacting in the CowAuth project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/mickey13/cow-auth/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'cow_auth'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
8
8
|
|
9
9
|
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require
|
10
|
+
# require 'pry'
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
14
|
-
IRB.start
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/cow_auth.gemspec
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
require 'cow_auth/version'
|
@@ -10,19 +10,21 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ['mickey@vt.edu']
|
11
11
|
|
12
12
|
spec.summary = 'Authentication gem'
|
13
|
-
spec.description = 'The main goal of this gem is to provide
|
14
|
-
spec.homepage = 'https://github.com/mickey13/
|
13
|
+
spec.description = 'The main goal of this gem is to provide token-based authentication for Rails (or Rails-like) web applications.'
|
14
|
+
spec.homepage = 'https://github.com/mickey13/cow-auth'
|
15
15
|
spec.license = 'MIT'
|
16
16
|
|
17
|
-
spec.files = `git ls-files -z`.split("\x0").reject
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
18
20
|
spec.bindir = 'exe'
|
19
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
22
|
spec.require_paths = ['lib']
|
21
23
|
|
22
|
-
spec.required_ruby_version = '~> 2.
|
24
|
+
spec.required_ruby_version = '~> 2.4'
|
23
25
|
|
24
26
|
spec.add_development_dependency 'bundler', '~> 1.16'
|
25
|
-
spec.add_development_dependency 'rake', '~>
|
26
|
-
spec.add_development_dependency 'minitest', '~> 5.
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
27
29
|
spec.add_runtime_dependency 'scrypt', '~> 3.0'
|
28
30
|
end
|
data/lib/cow_auth/user.rb
CHANGED
@@ -42,10 +42,12 @@ module CowAuth
|
|
42
42
|
auth_token: self.token_valid? ? self.auth_token : self.generate_auth_token,
|
43
43
|
expires_at: self.generate_token_expires_at
|
44
44
|
}.to_json)
|
45
|
+
return true
|
45
46
|
end
|
46
47
|
|
47
48
|
def api_sign_out
|
48
49
|
self.redis_handle.del(self.redis_key)
|
50
|
+
return true
|
49
51
|
end
|
50
52
|
|
51
53
|
def auth_token
|
data/lib/cow_auth/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cow_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mickey Cowden
|
@@ -30,28 +30,28 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '10.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '5.
|
47
|
+
version: '5.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '5.
|
54
|
+
version: '5.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: scrypt
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,8 +66,8 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.0'
|
69
|
-
description: The main goal of this gem is to provide
|
70
|
-
|
69
|
+
description: The main goal of this gem is to provide token-based authentication for
|
70
|
+
Rails (or Rails-like) web applications.
|
71
71
|
email:
|
72
72
|
- mickey@vt.edu
|
73
73
|
executables: []
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- ".travis.yml"
|
79
79
|
- CODE_OF_CONDUCT.md
|
80
80
|
- Gemfile
|
81
|
+
- Gemfile.lock
|
81
82
|
- LICENSE.txt
|
82
83
|
- README.md
|
83
84
|
- Rakefile
|
@@ -90,7 +91,7 @@ files:
|
|
90
91
|
- lib/cow_auth/token_auth/session_endpoints.rb
|
91
92
|
- lib/cow_auth/user.rb
|
92
93
|
- lib/cow_auth/version.rb
|
93
|
-
homepage: https://github.com/mickey13/
|
94
|
+
homepage: https://github.com/mickey13/cow-auth
|
94
95
|
licenses:
|
95
96
|
- MIT
|
96
97
|
metadata: {}
|
@@ -102,7 +103,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
103
|
requirements:
|
103
104
|
- - "~>"
|
104
105
|
- !ruby/object:Gem::Version
|
105
|
-
version: '2.
|
106
|
+
version: '2.4'
|
106
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
108
|
requirements:
|
108
109
|
- - ">="
|