glogin 0.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a6930e668b924c169ed5c02ac91b366edfa64cb
4
- data.tar.gz: ad7c1628b4e3508c39b5c6c14c36a4deb79d04fd
3
+ metadata.gz: 39525c79b9353af1f2baa96306fd38ee13d73796
4
+ data.tar.gz: 3ae939f552d4ab34bb6b26de01b23b9944ac773d
5
5
  SHA512:
6
- metadata.gz: 2504f72c9222bcd65676148017cd18d4e0ff985f42fc2f3967544eced7e8928b67ec5e3abec0c2b481c20799d8274b82e3d6a9cd1b08de6bf130472a297e3617
7
- data.tar.gz: 815f03f93317871b300a72432edb448a77a223a1912ca1ad4f0c9ad7451e18702673d4fde83b6da0f3c573ad76e7e96805f1126e42458d08f5123cf2e852f5ed
6
+ metadata.gz: ecbacab1006d2c2cab12dce480cc7a6e2948c0d3977b7ab8570c5deafc939f822885a17c584bcbb65341e1d45e5bb1f623c69a4f62ebabc78e39b1d4badb7506
7
+ data.tar.gz: b9a115d1c87718cece3763ededbe430ac7b6dcf5f52ec8b12242ae40cf0e6081a2a8fa474678e4685f615c08bbbd9b89b67404ebed1048c7c3093b061d8f75eb
data/README.md CHANGED
@@ -23,11 +23,11 @@ First, somewhere in the global space, before the app starts:
23
23
  require 'glogin'
24
24
  configure do
25
25
  set :glogin, GLogin::Auth.new(
26
- // Make sure their values are coming from a secure
27
- // place and are not visible in the source code:
26
+ # Make sure their values are coming from a secure
27
+ # place and are not visible in the source code:
28
28
  client_id, client_secret,
29
- // This is what you will register in GitHub as an
30
- // authorization callback URL:
29
+ # This is what you will register in GitHub as an
30
+ # authorization callback URL:
31
31
  'http://www.example.com/github-callback'
32
32
  )
33
33
  end
@@ -43,8 +43,8 @@ before '/*' do
43
43
  begin
44
44
  @user = Cookie::Closed.new(
45
45
  cookies[:glogin],
46
- // This must be some long text to be used to
47
- // encrypt the value in the cookie.
46
+ # This must be some long text to be used to
47
+ # encrypt the value in the cookie.
48
48
  secret
49
49
  ).to_user
50
50
  rescue OpenSSL::Cipher::CipherError => _
@@ -67,7 +67,7 @@ Next, we need a URL for GitHub OAuth callback:
67
67
  get '/github-callback' do
68
68
  cookies[:glogin] = Cookie::Open.new(
69
69
  settings.glogin.user(params[:code]),
70
- // The same encryption secret that we were using above:
70
+ # The same encryption secret that we were using above:
71
71
  secret
72
72
  ).to_s
73
73
  redirect to('/')
@@ -41,17 +41,19 @@ module GLogin
41
41
  end
42
42
 
43
43
  def to_user
44
- if @secret.empty?
45
- @text
46
- else
47
- cpr = Cookie.cipher
48
- cpr.decrypt
49
- cpr.key = Digest::SHA1.hexdigest(@secret)
50
- decrypted = cpr.update(Base64.decode64(@text))
51
- decrypted << cpr.final
52
- parts = decrypted.to_s.split('|')
53
- { login: parts[0], avatar: parts[1] }
54
- end
44
+ plain =
45
+ if @secret.empty?
46
+ @text
47
+ else
48
+ cpr = Cookie.cipher
49
+ cpr.decrypt
50
+ cpr.key = Digest::SHA1.hexdigest(@secret)
51
+ decrypted = cpr.update(Base64.decode64(@text))
52
+ decrypted << cpr.final
53
+ decrypted.to_s
54
+ end
55
+ parts = plain.split('|')
56
+ { login: parts[0], avatar: parts[1] }
55
57
  end
56
58
  end
57
59
 
@@ -25,5 +25,5 @@
25
25
  # Copyright:: Copyright (c) 2017 Yegor Bugayenko
26
26
  # License:: MIT
27
27
  module GLogin
28
- VERSION = '0.2'.freeze
28
+ VERSION = '0.2.1'.freeze
29
29
  end
@@ -40,6 +40,14 @@ class TestCookie < Minitest::Test
40
40
  assert_equal(user[:avatar], 'https://avatars1.githubusercontent.com/u/526301')
41
41
  end
42
42
 
43
+ def test_decrypts_in_test_mode
44
+ user = GLogin::Cookie::Closed.new(
45
+ 'test|http://example.com', ''
46
+ ).to_user
47
+ assert_equal(user[:login], 'test')
48
+ assert_equal(user[:avatar], 'http://example.com')
49
+ end
50
+
43
51
  def test_fails_on_broken_text
44
52
  assert_raises OpenSSL::Cipher::CipherError do
45
53
  GLogin::Cookie::Closed.new(
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glogin
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko