glogin 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.simplecov +1 -1
- data/Gemfile +1 -1
- data/LICENSE.txt +1 -1
- data/README.md +9 -8
- data/Rakefile +1 -1
- data/glogin.gemspec +1 -1
- data/lib/glogin.rb +2 -2
- data/lib/glogin/auth.rb +5 -2
- data/lib/glogin/cookie.rb +2 -2
- data/lib/glogin/version.rb +3 -3
- data/test/glogin/test_auth.rb +1 -1
- data/test/glogin/test_cookie.rb +1 -1
- data/test/test__helper.rb +1 -1
- data/test/test_glogin.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 344fc68993c5eb7e5234ee2039779ea46dabf2d5
|
4
|
+
data.tar.gz: f01d6910ce8a3066b44ef18aceb4ebe2623cfcba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bed8f2877ddceae15a197f8ae0f81366b5cd0ac5d0e14f6389d9d5fc074f89ed537d915b670052c3a6442c589f119c8405b7313d92b08915fa43b10b95ea3ee
|
7
|
+
data.tar.gz: f223e37df06787e2a948372fff840ed77ec4fa30de65e0e63725db859ffc981e878fdda8748f60ab6a2486e000049055d58ec0a2c35032b2aafad37a1d3ca542
|
data/.simplecov
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
#
|
3
|
-
# Copyright (c) 2017 Yegor Bugayenko
|
3
|
+
# Copyright (c) 2017-2018 Yegor Bugayenko
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
data/Gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
#
|
3
|
-
# Copyright (c) 2017 Yegor Bugayenko
|
3
|
+
# Copyright (c) 2017-2018 Yegor Bugayenko
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -41,20 +41,21 @@ require 'sinatra/cookies'
|
|
41
41
|
before '/*' do
|
42
42
|
if cookies[:glogin]
|
43
43
|
begin
|
44
|
-
@user = Cookie::Closed.new(
|
44
|
+
@user = GLogin::Cookie::Closed.new(
|
45
45
|
cookies[:glogin],
|
46
46
|
# This must be some long text to be used to
|
47
47
|
# encrypt the value in the cookie.
|
48
48
|
secret
|
49
49
|
).to_user
|
50
50
|
rescue OpenSSL::Cipher::CipherError => _
|
51
|
-
|
51
|
+
# Nothing happens here, the user is not logged in.
|
52
|
+
cookies.delete(:glogin)
|
52
53
|
end
|
53
54
|
end
|
54
55
|
end
|
55
56
|
```
|
56
57
|
|
57
|
-
If the `glogin` cookie is coming
|
58
|
+
If the `glogin` cookie is coming in and contains a valid data,
|
58
59
|
a local variable `@user` will be set to something like this:
|
59
60
|
|
60
61
|
```ruby
|
@@ -65,7 +66,7 @@ Next, we need a URL for GitHub OAuth callback:
|
|
65
66
|
|
66
67
|
```ruby
|
67
68
|
get '/github-callback' do
|
68
|
-
cookies[:glogin] = Cookie::Open.new(
|
69
|
+
cookies[:glogin] = GLogin::Cookie::Open.new(
|
69
70
|
settings.glogin.user(params[:code]),
|
70
71
|
# The same encryption secret that we were using above:
|
71
72
|
secret
|
@@ -91,12 +92,12 @@ settings.glogin.login_uri
|
|
91
92
|
```
|
92
93
|
|
93
94
|
For unit testing you can just provide an empty string as a `secret` for
|
94
|
-
`Cookie::Open` and `Cookie::Closed` and the encryption will be disabled:
|
95
|
+
`GLogin::Cookie::Open` and `GLogin::Cookie::Closed` and the encryption will be disabled:
|
95
96
|
whatever will be coming from the cookie will be trusted.
|
96
97
|
|
97
98
|
I use this gem in [sixnines](https://github.com/yegor256/sixnines)
|
98
|
-
and [0pdd](https://github.com/yegor256/0pdd) web apps
|
99
|
-
|
99
|
+
and [0pdd](https://github.com/yegor256/0pdd) web apps (both open source),
|
100
|
+
on top of Sinatra.
|
100
101
|
|
101
102
|
## How to contribute?
|
102
103
|
|
@@ -106,7 +107,7 @@ Just submit a pull request. Make sure `rake` passes.
|
|
106
107
|
|
107
108
|
(The MIT License)
|
108
109
|
|
109
|
-
Copyright (c) 2017 Yegor Bugayenko
|
110
|
+
Copyright (c) 2017-2018 Yegor Bugayenko
|
110
111
|
|
111
112
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
112
113
|
of this software and associated documentation files (the 'Software'), to deal
|
data/Rakefile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
#
|
3
|
-
# Copyright (c) 2017 Yegor Bugayenko
|
3
|
+
# Copyright (c) 2017-2018 Yegor Bugayenko
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
data/glogin.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
#
|
3
|
-
# Copyright (c) 2017 Yegor Bugayenko
|
3
|
+
# Copyright (c) 2017-2018 Yegor Bugayenko
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
data/lib/glogin.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
#
|
3
|
-
# Copyright (c) 2017 Yegor Bugayenko
|
3
|
+
# Copyright (c) 2017-2018 Yegor Bugayenko
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -27,7 +27,7 @@ require_relative 'glogin/cookie'
|
|
27
27
|
|
28
28
|
# GLogin main module.
|
29
29
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
30
|
-
# Copyright:: Copyright (c) 2017 Yegor Bugayenko
|
30
|
+
# Copyright:: Copyright (c) 2017-2018 Yegor Bugayenko
|
31
31
|
# License:: MIT
|
32
32
|
module GLogin
|
33
33
|
end
|
data/lib/glogin/auth.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
#
|
3
|
-
# Copyright (c) 2017 Yegor Bugayenko
|
3
|
+
# Copyright (c) 2017-2018 Yegor Bugayenko
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -28,7 +28,7 @@ require 'cgi'
|
|
28
28
|
|
29
29
|
# GLogin main module.
|
30
30
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
31
|
-
# Copyright:: Copyright (c) 2017 Yegor Bugayenko
|
31
|
+
# Copyright:: Copyright (c) 2017-2018 Yegor Bugayenko
|
32
32
|
# License:: MIT
|
33
33
|
module GLogin
|
34
34
|
#
|
@@ -40,6 +40,7 @@ module GLogin
|
|
40
40
|
@id = id
|
41
41
|
raise "GitHub client secret can't be nil" if secret.nil?
|
42
42
|
@secret = secret
|
43
|
+
raise "Redirect URL can't be nil" if redirect.nil?
|
43
44
|
@redirect = redirect
|
44
45
|
end
|
45
46
|
|
@@ -51,6 +52,7 @@ module GLogin
|
|
51
52
|
end
|
52
53
|
|
53
54
|
def user(code)
|
55
|
+
raise 'Code can\'t be nil' if code.nil?
|
54
56
|
uri = URI.parse('https://api.github.com/user')
|
55
57
|
http = Net::HTTP.new(uri.host, uri.port)
|
56
58
|
http.use_ssl = true
|
@@ -66,6 +68,7 @@ module GLogin
|
|
66
68
|
private
|
67
69
|
|
68
70
|
def access_token(code)
|
71
|
+
raise 'Code can\'t be nil' if code.nil?
|
69
72
|
uri = URI.parse('https://github.com/login/oauth/access_token')
|
70
73
|
http = Net::HTTP.new(uri.host, uri.port)
|
71
74
|
http.use_ssl = true
|
data/lib/glogin/cookie.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
#
|
3
|
-
# Copyright (c) 2017 Yegor Bugayenko
|
3
|
+
# Copyright (c) 2017-2018 Yegor Bugayenko
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -26,7 +26,7 @@ require 'base64'
|
|
26
26
|
|
27
27
|
# GLogin main module.
|
28
28
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
29
|
-
# Copyright:: Copyright (c) 2017 Yegor Bugayenko
|
29
|
+
# Copyright:: Copyright (c) 2017-2018 Yegor Bugayenko
|
30
30
|
# License:: MIT
|
31
31
|
module GLogin
|
32
32
|
#
|
data/lib/glogin/version.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
#
|
3
|
-
# Copyright (c) 2017 Yegor Bugayenko
|
3
|
+
# Copyright (c) 2017-2018 Yegor Bugayenko
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -22,8 +22,8 @@
|
|
22
22
|
|
23
23
|
# GLogin main module.
|
24
24
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
25
|
-
# Copyright:: Copyright (c) 2017 Yegor Bugayenko
|
25
|
+
# Copyright:: Copyright (c) 2017-2018 Yegor Bugayenko
|
26
26
|
# License:: MIT
|
27
27
|
module GLogin
|
28
|
-
VERSION = '0.2.
|
28
|
+
VERSION = '0.2.2'.freeze
|
29
29
|
end
|
data/test/glogin/test_auth.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
#
|
3
|
-
# Copyright (c) 2017 Yegor Bugayenko
|
3
|
+
# Copyright (c) 2017-2018 Yegor Bugayenko
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
data/test/glogin/test_cookie.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
#
|
3
|
-
# Copyright (c) 2017 Yegor Bugayenko
|
3
|
+
# Copyright (c) 2017-2018 Yegor Bugayenko
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
data/test/test__helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
#
|
3
|
-
# Copyright (c) 2017 Yegor Bugayenko
|
3
|
+
# Copyright (c) 2017-2018 Yegor Bugayenko
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
data/test/test_glogin.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
#
|
3
|
-
# Copyright (c) 2017 Yegor Bugayenko
|
3
|
+
# Copyright (c) 2017-2018 Yegor Bugayenko
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -25,7 +25,7 @@ require_relative '../lib/glogin'
|
|
25
25
|
|
26
26
|
# GLogin main module test.
|
27
27
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
28
|
-
# Copyright:: Copyright (c) 2017 Yegor Bugayenko
|
28
|
+
# Copyright:: Copyright (c) 2017-2018 Yegor Bugayenko
|
29
29
|
# License:: MIT
|
30
30
|
class TestGLogin < Minitest::Test
|
31
31
|
def test_basic
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|