cow_auth 0.1.1 → 0.1.2
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/lib/cow_auth/authentication.rb +4 -6
- data/lib/cow_auth/not_authenticated_error.rb +4 -0
- data/lib/cow_auth/session.rb +7 -6
- data/lib/cow_auth/user.rb +4 -15
- data/lib/cow_auth/version.rb +1 -1
- data/lib/cow_auth.rb +2 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bde8798e339337d6f36ff9501e53cd585f79937
|
4
|
+
data.tar.gz: 4778ac785e62c819ff028c55d8027c940d9d78a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a340166bbe215adbf73ce3fe211a48d34c94db184cde1c2c3b2ed8ef541f1ac39bc6a8b33ed86e83748ff5fc67e02597dfbdd7b6e5ae09b94ac40daf705b9a79
|
7
|
+
data.tar.gz: 03f15f6a5cee66db6b30404d602f4bb3188a30c3c60d01d34ffe8167dbb1a8548a7210e98e15da13e88c665157fb039765d955a1df164abfc295bbc5aa88cee2
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'cow_auth/not_authenticated_error'
|
2
|
+
|
1
3
|
module CowAuth
|
2
4
|
module Authentication
|
3
5
|
extend ActiveSupport::Concern
|
@@ -9,13 +11,9 @@ module CowAuth
|
|
9
11
|
authenticate_or_request_with_http_token do |api_key, options|
|
10
12
|
sid, auth_token = api_key.match(/sid=([[:alnum:]]*)&auth_token=([[:alnum:]]*)/).try(:captures)
|
11
13
|
@current_user = User.authenticate_from_token(sid, auth_token)
|
14
|
+
raise CowAuth::NotAuthenticatedError.new('User not authenticated.') if @current_user.blank?
|
15
|
+
return true
|
12
16
|
end
|
13
17
|
end
|
14
|
-
|
15
|
-
def request_http_token_authentication(realm = 'Application', message = nil)
|
16
|
-
message ||= 'HTTP Token: Access denied.'
|
17
|
-
self.headers['WWW-Authenticate'] = %(Token realm="#{realm.tr('"'.freeze, ''.freeze)}")
|
18
|
-
self.__send__ :render, json: { error: message }, status: :unauthorized
|
19
|
-
end
|
20
18
|
end
|
21
19
|
end
|
data/lib/cow_auth/session.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
|
+
require 'cow_auth/not_authenticated_error'
|
2
|
+
|
1
3
|
module CowAuth
|
2
4
|
module Session
|
3
5
|
extend ActiveSupport::Concern
|
4
6
|
|
5
7
|
def create
|
6
|
-
user = User.find_by(email: params[:email])
|
7
|
-
if user.try(:authenticate, params[:password])
|
8
|
-
user.api_sign_in
|
9
|
-
render json: user
|
8
|
+
@user = User.find_by(email: params[:email])
|
9
|
+
if @user.try(:authenticate, params[:password])
|
10
|
+
@user.api_sign_in
|
10
11
|
else
|
11
|
-
|
12
|
+
raise CowAuth::NotAuthenticatedError.new('Invalid user credentials.')
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
@@ -16,7 +17,7 @@ module CowAuth
|
|
16
17
|
if @current_user.try(:api_sign_out)
|
17
18
|
head :ok
|
18
19
|
else
|
19
|
-
|
20
|
+
raise CowAuth::NotAuthenticatedError.new('Could not sign user out.')
|
20
21
|
end
|
21
22
|
end
|
22
23
|
end
|
data/lib/cow_auth/user.rb
CHANGED
@@ -39,6 +39,10 @@ module CowAuth
|
|
39
39
|
$redis.del(self.redis_key)
|
40
40
|
end
|
41
41
|
|
42
|
+
def auth_token
|
43
|
+
return User.fetch_api_key_from_redis(self.sid).try(:[], :auth_token)
|
44
|
+
end
|
45
|
+
|
42
46
|
def self.authenticate_from_token(sid, auth_token)
|
43
47
|
api_key = User.fetch_api_key_from_redis(sid)
|
44
48
|
if api_key.present? && api_key.key?(:auth_token) && api_key.key?(:expires_at) && api_key[:auth_token] == auth_token && api_key[:expires_at] > Time.zone.now
|
@@ -47,21 +51,6 @@ module CowAuth
|
|
47
51
|
return nil
|
48
52
|
end
|
49
53
|
|
50
|
-
def as_json(options = nil)
|
51
|
-
return {
|
52
|
-
uuid: self.uuid,
|
53
|
-
email: self.email,
|
54
|
-
sid: self.sid,
|
55
|
-
auth_token: User.fetch_api_key_from_redis(self.sid).try(:[], :auth_token),
|
56
|
-
first_name: self.first_name,
|
57
|
-
last_name: self.last_name,
|
58
|
-
sign_in_count: self.sign_in_count,
|
59
|
-
is_approved: self.is_approved,
|
60
|
-
created_at: self.created_at,
|
61
|
-
updated_at: self.updated_at
|
62
|
-
}
|
63
|
-
end
|
64
|
-
|
65
54
|
protected
|
66
55
|
|
67
56
|
def redis_key
|
data/lib/cow_auth/version.rb
CHANGED
data/lib/cow_auth.rb
CHANGED
@@ -2,9 +2,10 @@ require 'cow_auth/version'
|
|
2
2
|
require 'cow_auth/user'
|
3
3
|
require 'cow_auth/session'
|
4
4
|
require 'cow_auth/authentication'
|
5
|
+
require 'cow_auth/not_authenticated_error'
|
5
6
|
|
6
7
|
module CowAuth
|
7
|
-
def self.
|
8
|
+
def self.moo
|
8
9
|
user = CowAuth::User.new
|
9
10
|
puts user
|
10
11
|
return user
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cow_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mickey Cowden
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- cow_auth.gemspec
|
86
86
|
- lib/cow_auth.rb
|
87
87
|
- lib/cow_auth/authentication.rb
|
88
|
+
- lib/cow_auth/not_authenticated_error.rb
|
88
89
|
- lib/cow_auth/session.rb
|
89
90
|
- lib/cow_auth/user.rb
|
90
91
|
- lib/cow_auth/version.rb
|