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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0b57ef3a388ead6fcc8fe8e8190157e89c0214b0
4
- data.tar.gz: 0328b20840eb90b73774516125f8724964c1300e
3
+ metadata.gz: fd56a1c1350f2da23440fde9b04103163727691b
4
+ data.tar.gz: 72709aa891100174dc2a369f0e6d9e80d1d31429
5
5
  SHA512:
6
- metadata.gz: 0acd2c26505f320260aa89476ae7945b4fb414462213e105ac375f7e77b86d76fce1ce2ec78bd5883210c237ba0a832807624fb64e20f87b4de65f5437ac951d
7
- data.tar.gz: 1aabfb8da8538066f3dfb94628bf9e82c51c19d956ee7c003bdb4c0693ca1b5a8438940fdd59582e671d59ba73f119a00d42a87515926e31f4889e7b179dd487
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
- Add the **GITHUB_TEAM_ID** variable to your environment, in addition to GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET. For local development I recommend the [dotenv](https://github.com/bkeepers/dotenv) gem.
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, ENV['GITHUB_CLIENT_ID'], ENV['GITHUB_CLIENT_SECRET'], :scope => 'user'
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 an employee or not
28
- by checking the returned credentials object `request.env['omniauth.auth'].credentials.team_member?`.
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.team_member?
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, ENV['GITHUB_CLIENT_ID'], ENV['GITHUB_CLIENT_SECRET']
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
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module GitHubTeamMember
3
- VERSION = '1.0.2'
3
+ VERSION = '2.0.0'
4
4
  end
5
5
  end
@@ -4,18 +4,23 @@ module OmniAuth
4
4
  module Strategies
5
5
  class GitHubTeamMember < OmniAuth::Strategies::GitHub
6
6
  credentials do
7
- { 'team_member?' => github_team_member?(team_id) }
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 github_team_member?(id)
11
- response = access_token.get("/teams/#{id}/members/#{raw_info['login']}")
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 team_id
18
- ENV["GITHUB_TEAM_ID"]
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-github-team-member
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garrett Bjerkhoel