github-api-auth 0.1.0 → 0.2.0

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: ec1a20be8f8c517e329620ff1bdb7125ecb05f9b
4
- data.tar.gz: 55c52ac500e87dd78e3f81d5b2d1c121c79baf13
3
+ metadata.gz: b27153fa201eceb08dae38530627b21deecee767
4
+ data.tar.gz: 1c3bd842cd58c4171aab436bcf03fcd535acaea8
5
5
  SHA512:
6
- metadata.gz: ab6746507501209a59fc87ff9347b3dfcbb85339a1fa64da16e4c77d136c06a2182f7aad03642cc561f2d67cb7ce6ce713bd78729de005f108ba15db0e267862
7
- data.tar.gz: b65578d6f7a1b50e690223deabdea4fea975e1a5c313b4755731a1c21967490dd19611ae1396a305d3c23f353c9669a4e0d5b8dc556cf4aeefc23a04f700747d
6
+ metadata.gz: 960a9f15210d7e98fbc8355c4c49982d872e1b12c11706b3d3a8bf8d3aca8f022795d03bf5fdaed20ad5514b22ea077589375117052855fe55469a9c485f54c9
7
+ data.tar.gz: bcf8f0437dc2981904458b7c07e114c76fbcdab0dbaf90255e78ed30c33a8b8530875f48153cd6434a87e2853851a672b8bb966dc647d7c4b0979be19491c233
data/.gitignore CHANGED
@@ -20,3 +20,4 @@ tmp
20
20
  *.o
21
21
  *.a
22
22
  mkmf.log
23
+ .github_token
data/README.md CHANGED
@@ -18,12 +18,20 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- octo_client = Github::Api::Auth.new.github
21
+ require 'github/api/auth'
22
+ octo_client = Github::Api::Auth.new(scopes: ['user', 'repo']).github
22
23
 
23
24
  And you are good to go. It will ask you for login and password and store newly created access token in local file. If OTP is required it will initiate code send process and will ask for code.
24
25
 
26
+ Option `scopes` defaults to `repo:status`.
27
+
25
28
  ## Changelog
26
29
 
30
+ 0.2.0
31
+
32
+ - Added scopes option
33
+ - Cleaned code from external things
34
+
27
35
  0.1.0
28
36
 
29
37
  - Added basic authentication
@@ -9,13 +9,14 @@ module Github::Api::Auth
9
9
  AUTH_LOCAL_FILE = ".github_token"
10
10
  SCOPES = "repo:status"
11
11
 
12
- attr_accessor :github
12
+ attr_accessor :github, :scopes
13
13
 
14
- def self.new
15
- Github::Api::Auth::Klass.new
14
+ def self.new(scopes: SCOPES)
15
+ Github::Api::Auth::Klass.new(scopes: scopes)
16
16
  end
17
17
 
18
- def initialize
18
+ def initialize(scopes: [])
19
+ @scopes = scopes
19
20
  authenticate
20
21
  end
21
22
 
@@ -44,7 +45,6 @@ module Github::Api::Auth
44
45
  end
45
46
 
46
47
  def create_access_token
47
- scopes = SCOPES
48
48
  note = gen_token_note
49
49
  github.create_authorization(scopes: scopes, note: note)
50
50
  rescue Octokit::OneTimePasswordRequired => e
@@ -64,6 +64,6 @@ module Github::Api::Auth
64
64
  # TODO Make this use existing token instead of creating new one
65
65
  # NOTE We need this number if user want to authenticate multiple devices
66
66
  number = Time.now.to_i
67
- "Wimdu pre ci notifications #{number}"
67
+ "github-api-auth authorization #{number}"
68
68
  end
69
69
  end
@@ -1,7 +1,7 @@
1
1
  module Github
2
2
  module Api
3
3
  module Auth
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
6
6
  end
7
7
  end
@@ -58,7 +58,7 @@ RSpec.describe Github::Api::Auth do
58
58
  let(:password) { 'super strong password' }
59
59
  let(:client) { double('Octokit::Client') }
60
60
  let(:token) { '123456' }
61
- let(:authorization) { { scopes: 'repo:status', note: 'wimdu note' } }
61
+ let(:authorization) { { scopes: 'repo:status', note: 'super note' } }
62
62
  let(:otp) { '987654' }
63
63
 
64
64
  before do
@@ -69,7 +69,7 @@ RSpec.describe Github::Api::Auth do
69
69
  context 'having #configure_from_file failed' do
70
70
  before do
71
71
  allow_any_instance_of(subject).to receive(:configure_from_file) { false }
72
- allow_any_instance_of(subject).to receive(:gen_token_note) { 'wimdu note' }
72
+ allow_any_instance_of(subject).to receive(:gen_token_note) { 'super note' }
73
73
  allow_any_instance_of(subject).to receive(:ask).
74
74
  with('github username: ') { username }
75
75
  allow_any_instance_of(subject).to receive(:ask).
@@ -94,6 +94,18 @@ RSpec.describe Github::Api::Auth do
94
94
  github = subject.new
95
95
  end
96
96
 
97
+ describe 'scopes option' do
98
+ it 'allows to set scopes option for access token' do
99
+ allow_any_instance_of(subject).to receive(:gen_token_note) { 'crazy note' }
100
+ expect(client).to receive(:create_authorization).
101
+ with(scopes: ['user', 'repo'], note: 'crazy note') do
102
+ { token: '123456', scopes: ['user', 'repo'] }
103
+ end
104
+ github = subject.new(scopes: ['user', 'repo'])
105
+ expect(github.scopes).to eq(['user', 'repo'])
106
+ end
107
+ end
108
+
97
109
  context 'having one time password required' do
98
110
  it 'asks user for otp' do
99
111
  expect(client).to receive(:create_authorization).
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github-api-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Fedorov