intra 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -1
- data/intra.gemspec +1 -0
- data/lib/intra.rb +18 -24
- data/lib/intra/session.rb +39 -10
- data/lib/intra/version.rb +1 -1
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f45d8079fd761223276219cedbbc2c601658aa791af0b911349c33281fe8e2a
|
4
|
+
data.tar.gz: 567436e5ef554627a46a80b8ceac8e1c7ae3bc9896dc8bca7a3028a227178ed1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eaa01a2d6d4f1968e518662211c6e910cb887563cc429fa92f1a451fd41f0d2a1663b007a78ddb673d66805ff1109da232144b3418ce2234fcfbe5167646f994
|
7
|
+
data.tar.gz: e430fb2159fa71d8f186532562a541aaf697598af19137c96f017f8cd527325cbaf044f165c43fe85fc62afcf3e6a8e8f080bff6ce202de88a1c11134de23936
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
intra (0.1.
|
4
|
+
intra (0.1.2)
|
5
5
|
omniauth
|
6
6
|
omniauth-google-oauth2
|
7
7
|
rails
|
@@ -136,6 +136,7 @@ GEM
|
|
136
136
|
sqlite3 (1.4.1)
|
137
137
|
thor (0.20.3)
|
138
138
|
thread_safe (0.3.6)
|
139
|
+
timecop (0.9.1)
|
139
140
|
tzinfo (1.2.5)
|
140
141
|
thread_safe (~> 0.1)
|
141
142
|
websocket-driver (0.7.1)
|
@@ -152,6 +153,7 @@ DEPENDENCIES
|
|
152
153
|
minitest (~> 5.0)
|
153
154
|
rake (~> 10.0)
|
154
155
|
sqlite3
|
156
|
+
timecop
|
155
157
|
|
156
158
|
BUNDLED WITH
|
157
159
|
2.0.1
|
data/intra.gemspec
CHANGED
data/lib/intra.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
require 'logger'
|
2
|
-
require 'rails/engine'
|
1
|
+
require 'logger'
|
2
|
+
require 'rails/engine'
|
3
|
+
require 'action_dispatch'
|
3
4
|
require 'omniauth'
|
4
5
|
require 'omniauth-google-oauth2'
|
5
|
-
require 'action_dispatch'
|
6
6
|
|
7
7
|
require 'intra/version'
|
8
8
|
require 'intra/session'
|
@@ -13,30 +13,24 @@ require 'intra/request_forgery_protection'
|
|
13
13
|
require 'intra/engine'
|
14
14
|
|
15
15
|
module Intra
|
16
|
-
# Configure the path to redirect unauthenticated session. Default '/sign_in'
|
17
|
-
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.sign_in_path
|
22
|
-
@@sign_in_path ||= '/sign_in'
|
23
|
-
end
|
16
|
+
# Configure the path to redirect unauthenticated session. Default '/sign_in'.
|
17
|
+
mattr_accessor :sign_in_path
|
18
|
+
@@sign_in_path = '/sign_in'
|
24
19
|
|
25
20
|
# Configure the user class. Default 'User'
|
26
|
-
|
27
|
-
|
28
|
-
end
|
21
|
+
mattr_accessor :user_class
|
22
|
+
@@user_class = 'User'
|
29
23
|
|
30
|
-
|
31
|
-
|
32
|
-
|
24
|
+
# Configure the logger Intra will use. Defaults to Logger.new($STDOUT).
|
25
|
+
mattr_accessor :logger
|
26
|
+
@@logger = Logger.new($STDOUT)
|
33
27
|
|
34
|
-
#
|
35
|
-
|
36
|
-
|
37
|
-
end
|
28
|
+
# The session cookie expiration.
|
29
|
+
mattr_accessor :remember_for
|
30
|
+
@@remember_for = 2.weeks
|
38
31
|
|
39
|
-
|
40
|
-
|
41
|
-
|
32
|
+
# Time interval to timeout the user sesion without activity.
|
33
|
+
# Set this to nil if you do not want to timeout the user serssion.
|
34
|
+
mattr_accessor :timeout_in
|
35
|
+
@@timeout_in = 30.minutes
|
42
36
|
end
|
data/lib/intra/session.rb
CHANGED
@@ -4,12 +4,15 @@ module Intra
|
|
4
4
|
@env = env
|
5
5
|
@current_user = nil
|
6
6
|
@cookies = nil
|
7
|
+
check_timeout
|
7
8
|
end
|
8
9
|
|
9
10
|
def add_cookie_to_headers(headers)
|
10
11
|
if current_user&.remember_token
|
11
|
-
|
12
|
-
|
12
|
+
value = cookie_value
|
13
|
+
value['remember_token'] = current_user.remember_token
|
14
|
+
options = cookie_options.merge value: value.to_json
|
15
|
+
Rack::Utils.set_cookie_header! headers, INTRA_COOKIE, options
|
13
16
|
end
|
14
17
|
end
|
15
18
|
|
@@ -28,7 +31,7 @@ module Intra
|
|
28
31
|
current_user.reset_remember_token! if signed_in?
|
29
32
|
|
30
33
|
@current_user = nil
|
31
|
-
cookies.delete
|
34
|
+
cookies.delete INTRA_COOKIE
|
32
35
|
end
|
33
36
|
|
34
37
|
def signed_in?
|
@@ -39,29 +42,55 @@ module Intra
|
|
39
42
|
!signed_in?
|
40
43
|
end
|
41
44
|
|
45
|
+
def check_timeout
|
46
|
+
sign_out if timed_out?
|
47
|
+
end
|
48
|
+
|
42
49
|
private
|
43
50
|
|
44
|
-
def
|
45
|
-
Intra.
|
51
|
+
def timed_out?
|
52
|
+
return false unless Intra.timeout_in.present?
|
53
|
+
return false unless last_activity_at.present?
|
54
|
+
|
55
|
+
Time.current - Intra.timeout_in > last_activity_at
|
56
|
+
end
|
57
|
+
|
58
|
+
def cookie
|
59
|
+
@cookie ||= JSON.parse cookies[INTRA_COOKIE] rescue {}
|
60
|
+
end
|
61
|
+
|
62
|
+
def remember_token
|
63
|
+
cookie['remember_token']
|
64
|
+
end
|
65
|
+
|
66
|
+
def last_activity_at
|
67
|
+
cookie['last_activity_at']
|
46
68
|
end
|
47
69
|
|
48
70
|
def cookies
|
49
71
|
@cookies ||= ActionDispatch::Request.new(@env).cookie_jar
|
50
72
|
end
|
51
73
|
|
52
|
-
def
|
53
|
-
|
74
|
+
def user_model
|
75
|
+
Intra.user_class.constantize
|
54
76
|
end
|
55
77
|
|
56
78
|
def cookie_options
|
57
79
|
{
|
58
|
-
expires:
|
80
|
+
expires: Intra.remember_for.from_now,
|
59
81
|
path: '/',
|
60
82
|
secure: Rails.env.production?,
|
61
|
-
value:
|
83
|
+
value: cookie_value.to_json
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
def cookie_value
|
88
|
+
{
|
89
|
+
remember_token: remember_token,
|
90
|
+
last_activity_at: Time.current
|
62
91
|
}
|
63
92
|
end
|
64
93
|
|
65
|
-
|
94
|
+
INTRA_COOKIE = '_intra_cookie'.freeze
|
66
95
|
end
|
67
96
|
end
|
data/lib/intra/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: intra
|
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
|
- Scott Serok
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: timecop
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
125
139
|
description: Many companies have internal apps to support their day to day operations.
|
126
140
|
This library is a drop-in Google OAuth authentication and session management library
|
127
141
|
so you don't have to install Devise.
|