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 +4 -4
- data/.gitignore +1 -0
- data/README.md +9 -1
- data/lib/github/api/auth/auth.rb +6 -6
- data/lib/github/api/auth/version.rb +1 -1
- data/spec/github/api/auth/auth_spec.rb +14 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b27153fa201eceb08dae38530627b21deecee767
|
4
|
+
data.tar.gz: 1c3bd842cd58c4171aab436bcf03fcd535acaea8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 960a9f15210d7e98fbc8355c4c49982d872e1b12c11706b3d3a8bf8d3aca8f022795d03bf5fdaed20ad5514b22ea077589375117052855fe55469a9c485f54c9
|
7
|
+
data.tar.gz: bcf8f0437dc2981904458b7c07e114c76fbcdab0dbaf90255e78ed30c33a8b8530875f48153cd6434a87e2853851a672b8bb966dc647d7c4b0979be19491c233
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -18,12 +18,20 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
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
|
data/lib/github/api/auth/auth.rb
CHANGED
@@ -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
|
-
"
|
67
|
+
"github-api-auth authorization #{number}"
|
68
68
|
end
|
69
69
|
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: '
|
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) { '
|
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).
|