glogin 0.4.0 → 0.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3c119e131499ee21da88734113b234d547954e07
4
- data.tar.gz: 1f8d5998346047a3c5d818b4d76510c1d23b5ef5
3
+ metadata.gz: 3b6d42a8a87bd2c5542bf6e7e3fb5e0e536fe600
4
+ data.tar.gz: 6fc0c7f81e4fe8775bf74801a4da4c39ecdd0432
5
5
  SHA512:
6
- metadata.gz: d49f67f6d1469db13a608e22c01bf3dda74065b5e9d95ef0c695fd321e79d81213b574a678d6f13c2894086aea3d2028c3221bd3a0a75017989866b058a85544
7
- data.tar.gz: 64ebc43231b37ef27f359384fef145ad4b6aac34f07c3003c183bb4a743fa7c724474583470cec6d8a9791f874579d9afc5fa10f7a0cf67f74d64041442232cb
6
+ metadata.gz: ffba5fb8d96cfaf2bbf18a761d171a1036a4ad93e8ab30b480b5b6b85aafe16232f8bd333e94c2537d877be52a444a238d0003127f42e6d34f14616edda13fd2
7
+ data.tar.gz: 8f1ad4b624062362a95de0ebd6bd0debfa129720b6a6a3307ed9638ac9e438656dbead9b344485ec8f7cdc77a0ef37462ae03fd07513fb954ba30670114e2e40
data/README.md CHANGED
@@ -1,12 +1,11 @@
1
- [![Managed by Zerocracy](http://www.zerocracy.com/badge.svg)](http://www.zerocracy.com)
1
+ [![Managed by Zerocracy](https://www.0crat.com/badge/C3RFVLU72.svg)](https://www.0crat.com/p/C3RFVLU72)
2
2
  [![DevOps By Rultor.com](http://www.rultor.com/b/yegor256/glogin)](http://www.rultor.com/p/yegor256/glogin)
3
3
  [![We recommend RubyMine](http://img.teamed.io/rubymine-recommend.svg)](https://www.jetbrains.com/ruby/)
4
4
 
5
5
  [![Build Status](https://travis-ci.org/yegor256/glogin.svg)](https://travis-ci.org/yegor256/glogin)
6
6
  [![PDD status](http://www.0pdd.com/svg?name=yegor256/glogin)](http://www.0pdd.com/p?name=yegor256/glogin)
7
7
  [![Gem Version](https://badge.fury.io/rb/glogin.svg)](http://badge.fury.io/rb/glogin)
8
- [![Dependency Status](https://gemnasium.com/yegor256/glogin.svg)](https://gemnasium.com/yegor256/glogin)
9
- [![Code Climate](http://img.shields.io/codeclimate/github/yegor256/glogin.svg)](https://codeclimate.com/github/yegor256/glogin)
8
+ [![Maintainability](https://api.codeclimate.com/v1/badges/155f86b639d155259219/maintainability)](https://codeclimate.com/github/yegor256/glogin/maintainability)
10
9
  [![Test Coverage](https://img.shields.io/codecov/c/github/yegor256/glogin.svg)](https://codecov.io/github/yegor256/glogin?branch=master)
11
10
 
12
11
  ## GitHub Login for Ruby web app
@@ -123,6 +122,15 @@ I use this gem in [sixnines](https://github.com/yegor256/sixnines)
123
122
  and [0pdd](https://github.com/yegor256/0pdd) web apps (both open source),
124
123
  on top of Sinatra.
125
124
 
125
+ Also, you can use `GLogin::Codec` just to encrypt/decrypt a piece of text:
126
+
127
+ ```ruby
128
+ require 'glogin/codec'
129
+ codec = GLogin:Codec.new('the secret')
130
+ encrypted = codec.encrypt('Hello, world!')
131
+ decrypted = codec.decrypt(encrypted)
132
+ ```
133
+
126
134
  ## How to contribute?
127
135
 
128
136
  Just submit a pull request. Make sure `rake` passes.
@@ -42,7 +42,7 @@ Gem::Specification.new do |s|
42
42
  s.homepage = 'http://github.com/yegor256/glogin'
43
43
  s.files = `git ls-files`.split($RS)
44
44
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
45
- s.test_files = s.files.grep(%r{^(test|features)/})
45
+ s.test_files = s.files.grep(%r{^(test)/})
46
46
  s.rdoc_options = ['--charset=UTF-8']
47
47
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
48
48
  s.add_development_dependency 'codecov', '~>0.1'
@@ -52,4 +52,5 @@ Gem::Specification.new do |s|
52
52
  s.add_development_dependency 'rspec-rails', '~>3.1'
53
53
  s.add_development_dependency 'rubocop', '~>0.57'
54
54
  s.add_development_dependency 'rubocop-rspec', '~>1.5'
55
+ s.add_development_dependency 'webmock', '~>3.4'
55
56
  end
@@ -21,7 +21,6 @@
21
21
 
22
22
  require 'net/http'
23
23
  require 'uri'
24
- require 'yaml'
25
24
  require 'json'
26
25
  require 'cgi'
27
26
 
@@ -81,7 +80,6 @@ module GLogin
81
80
  req['Accept'] = 'application/json'
82
81
  res = http.request(req)
83
82
  raise "Error (#{res.code}): #{res.body}" unless res.code == '200'
84
- puts res.body
85
83
  JSON.parse(res.body)['access_token']
86
84
  end
87
85
  end
@@ -39,6 +39,7 @@ module GLogin
39
39
  end
40
40
 
41
41
  def decrypt(text)
42
+ raise 'Text can\'t be nil' if text.nil?
42
43
  if @secret.empty?
43
44
  text
44
45
  else
@@ -56,6 +57,7 @@ module GLogin
56
57
  end
57
58
 
58
59
  def encrypt(text)
60
+ raise 'Text can\'t be nil' if text.nil?
59
61
  cpr = cipher
60
62
  cpr.encrypt
61
63
  cpr.key = digest
@@ -22,12 +22,16 @@
22
22
  require 'openssl'
23
23
  require 'digest/sha1'
24
24
  require 'base64'
25
+ require_relative 'codec'
25
26
 
26
27
  # GLogin main module.
27
28
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
28
29
  # Copyright:: Copyright (c) 2017-2018 Yegor Bugayenko
29
30
  # License:: MIT
30
31
  module GLogin
32
+ # Split symbol inside the cookie text
33
+ SPLIT = '|'.freeze
34
+
31
35
  #
32
36
  # Secure cookie
33
37
  #
@@ -49,14 +53,14 @@ module GLogin
49
53
  # to catch in your applicaiton and ignore the login attempt.
50
54
  def to_user
51
55
  plain = Codec.new(@secret).decrypt(@text)
52
- login, avatar, ctx = plain.split('|', 3)
56
+ login, avatar, bearer, ctx = plain.split(GLogin::SPLIT, 4)
53
57
  if !@secret.empty? && ctx.to_s != @context
54
58
  raise(
55
59
  OpenSSL::Cipher::CipherError,
56
60
  "Context '#{@context}' expected, but '#{ctx}' found"
57
61
  )
58
62
  end
59
- { login: login, avatar: avatar }
63
+ { login: login, avatar: avatar, bearer: bearer }
60
64
  end
61
65
  end
62
66
 
@@ -77,8 +81,9 @@ module GLogin
77
81
  [
78
82
  @json['login'],
79
83
  @json['avatar_url'],
84
+ @json['bearer'],
80
85
  @context
81
- ].join('|')
86
+ ].join(GLogin::SPLIT)
82
87
  )
83
88
  end
84
89
  end
@@ -24,5 +24,5 @@
24
24
  # Copyright:: Copyright (c) 2017-2018 Yegor Bugayenko
25
25
  # License:: MIT
26
26
  module GLogin
27
- VERSION = '0.4.0'.freeze
27
+ VERSION = '0.4.1'.freeze
28
28
  end
@@ -20,9 +20,29 @@
20
20
  # SOFTWARE.
21
21
 
22
22
  require 'minitest/autorun'
23
+ require 'webmock/minitest'
23
24
  require_relative '../../lib/glogin/cookie'
24
25
 
25
26
  class TestAuth < Minitest::Test
27
+ def test_authenticate_via_https
28
+ auth = GLogin::Auth.new('1234', '4433', 'https://example.org')
29
+ stub_request(:post, 'https://github.com/login/oauth/access_token').to_return(
30
+ status: 200,
31
+ body: {
32
+ access_token: 'some-token'
33
+ }.to_json
34
+ )
35
+ stub_request(:get, 'https://api.github.com/user').to_return(
36
+ status: 200,
37
+ body: {
38
+ auth_code: '437849732894732',
39
+ login: 'yegor256'
40
+ }.to_json
41
+ )
42
+ user = auth.user('437849732894732')
43
+ assert_equal('yegor256', user['login'])
44
+ end
45
+
26
46
  def test_login_uri
27
47
  auth = GLogin::Auth.new(
28
48
  'client_id', 'client_secret', 'http://www.example.com/github-oauth'
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.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-17 00:00:00.000000000 Z
11
+ date: 2018-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: codecov
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '1.5'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.4'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.4'
111
125
  description: Enables login/logout functionality for a Ruby web app
112
126
  email: yegor256@gmail.com
113
127
  executables: []