omniauth-github-team-member 1.0.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -12
- data/lib/omniauth-github-team-member/version.rb +1 -1
- data/lib/omniauth/strategies/github_team_member.rb +10 -5
- 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: fd56a1c1350f2da23440fde9b04103163727691b
|
4
|
+
data.tar.gz: 72709aa891100174dc2a369f0e6d9e80d1d31429
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c92a7366027c23158365de7b382c36185da38ee4a1ff4bfd5dfb0a7a86daa7265cdd6a9d862b0e2863d4d6a7d8eb495ea112ce4daccec27e1b972ecef79a230
|
7
|
+
data.tar.gz: 929e2d0914a8febbdf477b2bcedf9bfef78896ade2b072add6522cb87deca722acabef17db81acb694c83d675f6b4f84672e1e5c7aa1c514147a63b30dc54138
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@ Add the gem to your Gemfile and bundle.
|
|
12
12
|
gem "omniauth-github-team-member"
|
13
13
|
```
|
14
14
|
|
15
|
-
|
15
|
+
I like to store the GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET in my environment, but you don't have to if you have a preferred place to put keys and secrets. For local development I recommend the [dotenv](https://github.com/bkeepers/dotenv) gem for setting environment variables.
|
16
16
|
|
17
17
|
## Basic Usage
|
18
18
|
|
@@ -20,12 +20,18 @@ Usage in Rails:
|
|
20
20
|
|
21
21
|
```ruby
|
22
22
|
Rails.application.config.middleware.use OmniAuth::Builder do
|
23
|
-
provider :githubteammember,
|
23
|
+
provider :githubteammember,
|
24
|
+
ENV['GITHUB_CLIENT_ID'],
|
25
|
+
ENV['GITHUB_CLIENT_SECRET'],
|
26
|
+
:scope => 'user',
|
27
|
+
:teams => {
|
28
|
+
"mentors_team_member?" => 426344
|
29
|
+
}
|
24
30
|
end
|
25
31
|
```
|
26
32
|
|
27
|
-
During the callback phase, you can check to see if the authed user is
|
28
|
-
by checking the returned credentials object `request.env['omniauth.auth'].credentials.
|
33
|
+
During the callback phase, you can check to see if the authed user is on the mentors team or not
|
34
|
+
by checking the returned credentials object `request.env['omniauth.auth'].credentials.mentors_team_member?`.
|
29
35
|
|
30
36
|
An example of how to integrate this strategy with OmniAuth is below. Do note that these
|
31
37
|
examples are just guidelines, you will most likely need to change each example to match your application's needs.
|
@@ -50,7 +56,7 @@ class User < ActiveRecord::Base
|
|
50
56
|
# Prevents past team members from logging into existing accounts they
|
51
57
|
# created when they were previously a team member. Also ensures
|
52
58
|
# new accounts can't be created unless they are a team member.
|
53
|
-
return false unless access_token.credentials.
|
59
|
+
return false unless access_token.credentials.mentors_team_member?
|
54
60
|
|
55
61
|
info = access_token.info
|
56
62
|
github_id = access_token.uid
|
@@ -72,7 +78,13 @@ Usage in Sinatra:
|
|
72
78
|
|
73
79
|
```ruby
|
74
80
|
use OmniAuth::Builder do
|
75
|
-
provider :githubteammember,
|
81
|
+
provider :githubteammember,
|
82
|
+
ENV['GITHUB_CLIENT_ID'],
|
83
|
+
ENV['GITHUB_CLIENT_SECRET'],
|
84
|
+
:scope => 'user',
|
85
|
+
:teams => {
|
86
|
+
"mentors_team_member?" => 426344
|
87
|
+
}
|
76
88
|
end
|
77
89
|
```
|
78
90
|
|
@@ -81,12 +93,6 @@ end
|
|
81
93
|
You must require the user scope to be able to access the team data associated with
|
82
94
|
the authenticated user.
|
83
95
|
|
84
|
-
```ruby
|
85
|
-
use OmniAuth::Builder do
|
86
|
-
provider :githubteammember, ENV['GITHUB_CLIENT_ID'], ENV['GITHUB_CLIENT_SECRET'], :scope => 'user'
|
87
|
-
end
|
88
|
-
```
|
89
|
-
|
90
96
|
More info on [Scopes](http://developer.github.com/v3/oauth/#scopes).
|
91
97
|
|
92
98
|
## Contributing
|
@@ -4,18 +4,23 @@ module OmniAuth
|
|
4
4
|
module Strategies
|
5
5
|
class GitHubTeamMember < OmniAuth::Strategies::GitHub
|
6
6
|
credentials do
|
7
|
-
|
7
|
+
options['teams'].inject({}) do |base, key_value_pair|
|
8
|
+
method_name, team_id = key_value_pair
|
9
|
+
base[booleanize_method_name(method_name)] = team_member?(team_id)
|
10
|
+
base
|
11
|
+
end
|
8
12
|
end
|
9
13
|
|
10
|
-
def
|
11
|
-
response = access_token.get("/teams/#{
|
14
|
+
def team_member?(team_id)
|
15
|
+
response = access_token.get("/teams/#{team_id}/members/#{raw_info['login']}")
|
12
16
|
response.status == 204
|
13
17
|
rescue ::OAuth2::Error
|
14
18
|
false
|
15
19
|
end
|
16
20
|
|
17
|
-
def
|
18
|
-
|
21
|
+
def booleanize_method_name(method_name)
|
22
|
+
return method_name if method_name =~ /\?$/
|
23
|
+
return "#{method_name}?"
|
19
24
|
end
|
20
25
|
end
|
21
26
|
end
|