sinatra-portier 1.1.1 → 1.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/sinatra/browserid/helpers.rb +52 -0
- data/lib/sinatra/browserid/template.rb +19 -0
- data/lib/sinatra/portier.rb +3 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9cf7b340dc8102ec6a3f25c71b27c218da1aec5b
|
4
|
+
data.tar.gz: 7849e64624574bfa8f194a0d72707318d0bd153e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c3aaa1f45496587023639ffc3b0bb275c7abaaaabd8554f8d4cbca7309000bf4c25a685010209f932e451a353d1ef48018d7ab263e6280ba6bd79206029ee32
|
7
|
+
data.tar.gz: fe1e6802718f600c4267794d3ffb57d52a11945bb962e364b3ac479fa3c35fc0144af6c4781324724e646c9300a621f2c7eec0d05e15c67057589d7d67b91381
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Sinatra
|
2
|
+
module BrowserID
|
3
|
+
module Helpers
|
4
|
+
# Returns true if the current user has logged in and presented
|
5
|
+
# a valid assertion.
|
6
|
+
def authorized?
|
7
|
+
! session[:browserid_email].nil?
|
8
|
+
end
|
9
|
+
|
10
|
+
# If the current user is not logged in, redirects to a login
|
11
|
+
# page. Override the login page by setting the Sinatra
|
12
|
+
# option <tt>:browserid_login_url</tt>.
|
13
|
+
def authorize!
|
14
|
+
session[:authorize_redirect_url] = request.url
|
15
|
+
login_url = settings.browserid_login_url
|
16
|
+
redirect login_url unless authorized?
|
17
|
+
end
|
18
|
+
|
19
|
+
# Logs out the current user.
|
20
|
+
def logout!
|
21
|
+
session[:browserid_email] = nil
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns the BrowserID verified email address, or nil if the
|
25
|
+
# user is not logged in.
|
26
|
+
def authorized_email
|
27
|
+
session[:browserid_email]
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns the HTML to render the Persona login form.
|
31
|
+
# Optionally takes a URL parameter for where the user should
|
32
|
+
# be redirected to after the assert POST back.
|
33
|
+
def render_login_button(redirect_url = nil)
|
34
|
+
if session[:authorize_redirect_url]
|
35
|
+
redirect_url = session[:authorize_redirect_url]
|
36
|
+
session[:authorize_redirect_url] = nil
|
37
|
+
end
|
38
|
+
redirect_url ||= request.url
|
39
|
+
session['redirect_url'] = redirect_url
|
40
|
+
|
41
|
+
nonce = session[:nonce]
|
42
|
+
unless nonce
|
43
|
+
session[:nonce] = nonce = SecureRandom.base64
|
44
|
+
end
|
45
|
+
|
46
|
+
template = ERB.new(Templates::LOGIN_BUTTON)
|
47
|
+
template.result(binding)
|
48
|
+
end
|
49
|
+
end # module Helpers
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Sinatra
|
2
|
+
module BrowserID
|
3
|
+
module Templates
|
4
|
+
LOGIN_BUTTON = <<-EOF
|
5
|
+
<form action="<%= settings.browserid_url %>/auth" method="POST">
|
6
|
+
<input type=email name=login_hint placeholder="you@example.com" />
|
7
|
+
<input type=hidden name=scope value="openid email" />
|
8
|
+
<input type=hidden name=response_type value="id_token" />
|
9
|
+
<input type=hidden name=response_mode value="form_post" />
|
10
|
+
<input type=hidden name=client_id value="<%= request.base_url.chomp('/') %>" />
|
11
|
+
<input type=hidden name=redirect_uri value="<%= url '/_browserid_assert' %>" />
|
12
|
+
<input type=hidden name=nonce value="<%= nonce %>" />
|
13
|
+
<input type=submit value="Log In" />
|
14
|
+
</form>
|
15
|
+
EOF
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-portier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pete Fritchman
|
@@ -65,6 +65,9 @@ files:
|
|
65
65
|
- example/config.ru
|
66
66
|
- example/views/index.erb
|
67
67
|
- lib/sinatra/browserid.rb
|
68
|
+
- lib/sinatra/browserid/helpers.rb
|
69
|
+
- lib/sinatra/browserid/template.rb
|
70
|
+
- lib/sinatra/portier.rb
|
68
71
|
homepage: https://github.com/onli/sinatra-portier
|
69
72
|
licenses: []
|
70
73
|
metadata: {}
|