omniauth-github-team-member 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/Gemfile +12 -0
- data/Guardfile +10 -0
- data/README.md +90 -0
- data/Rakefile +12 -0
- data/lib/omniauth-github-team-member.rb +2 -0
- data/lib/omniauth-github-team-member/version.rb +5 -0
- data/lib/omniauth/strategies/github_team_member.rb +24 -0
- data/omniauth-github-team-member.gemspec +23 -0
- data/spec/omniauth/strategies/github_spec.rb +21 -0
- data/spec/omniauth/strategies/github_team_member_spec.rb +21 -0
- data/spec/spec_helper.rb +17 -0
- metadata +141 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/Gemfile
ADDED
data/Guardfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
# OmniAuth GitHubber Auth
|
2
|
+
|
3
|
+
This is the official OmniAuth strategy for authenticating to GitHub. To
|
4
|
+
use it, you'll need to sign up for an OAuth2 Application ID and Secret
|
5
|
+
on the [GitHub Applications Page](https://github.com/settings/applications).
|
6
|
+
|
7
|
+
## Installing
|
8
|
+
|
9
|
+
Add the gem to your Gemfile and bundle.
|
10
|
+
|
11
|
+
```
|
12
|
+
gem "omniauth-github-team-member"
|
13
|
+
```
|
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.
|
16
|
+
|
17
|
+
## Basic Usage
|
18
|
+
|
19
|
+
Usage in Rails:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
23
|
+
provider :github_team_member, ENV['GITHUB_CLIENT_ID'], ENV['GITHUB_CLIENT_SECRET'], :scope => 'user'
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
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?`.
|
29
|
+
|
30
|
+
An example of how to integrate this strategy with OmniAuth is below. Do note that these
|
31
|
+
examples are just guidelines, you will most likely need to change each example to match your application's needs.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
class SessionsController
|
35
|
+
def create
|
36
|
+
@user = User.find_for_github_team_oauth(request.env['omniauth.auth'])
|
37
|
+
|
38
|
+
if @user && @user.persisted?
|
39
|
+
redirect_to root_path
|
40
|
+
else
|
41
|
+
redirect_to no_access_path
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
class User < ActiveRecord::Base
|
49
|
+
def self.find_for_github_team_oauth(access_token, signed_in_resource=nil)
|
50
|
+
# Prevents past team members from logging into existing accounts they
|
51
|
+
# created when they were previously a team member. Also ensures
|
52
|
+
# new accounts can't be created unless they are a team member.
|
53
|
+
return false unless access_token.credentials.team_member?
|
54
|
+
|
55
|
+
info = access_token.info
|
56
|
+
github_id = access_token.uid
|
57
|
+
user = find_or_initialize_by_github_id(github_id)
|
58
|
+
|
59
|
+
if user.new_record?
|
60
|
+
user.name = info.name
|
61
|
+
user.email = info.email
|
62
|
+
user.github_identifier = info.nickname
|
63
|
+
user.save
|
64
|
+
end
|
65
|
+
|
66
|
+
user
|
67
|
+
end
|
68
|
+
end
|
69
|
+
```
|
70
|
+
|
71
|
+
Usage in Sinatra:
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
use OmniAuth::Builder do
|
75
|
+
provider :github_team_member, ENV['GITHUB_CLIENT_ID'], ENV['GITHUB_CLIENT_SECRET']
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
### Scopes
|
80
|
+
|
81
|
+
You must require the user scope to be able to access the team data associated with
|
82
|
+
the authenticated user.
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
use OmniAuth::Builder do
|
86
|
+
provider :github_team_member, ENV['GITHUB_CLIENT_ID'], ENV['GITHUB_CLIENT_SECRET'], :scope => 'user'
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
90
|
+
More info on [Scopes](http://developer.github.com/v3/oauth/#scopes).
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'omniauth-github'
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Strategies
|
5
|
+
class GitHubTeamMember < OmniAuth::Strategies::GitHub
|
6
|
+
credentials do
|
7
|
+
{ 'team_member?' => github_team_member?(team_id) }
|
8
|
+
end
|
9
|
+
|
10
|
+
def github_team_member?(id)
|
11
|
+
team_members = access_token.get("/teams/#{id}/members").parsed
|
12
|
+
!!team_members.detect { |member| member['login'] == raw_info['login'] }
|
13
|
+
rescue ::OAuth2::Error
|
14
|
+
false
|
15
|
+
end
|
16
|
+
|
17
|
+
def team_id
|
18
|
+
ENV["GITHUB_TEAM_ID"]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
OmniAuth.config.add_camelization "githubteammember", "GitHubTeamMember"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/omniauth-github-team-member/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ['Jonathan Hoyt']
|
6
|
+
gem.email = ['jonmagic@gmail.com']
|
7
|
+
gem.description = %q{OmniAuth strategy for GitHub Team Auth.}
|
8
|
+
gem.summary = %q{OmniAuth strategy for GitHub Team Auth.}
|
9
|
+
gem.homepage = 'https://github.com/jonmagic/omniauth-github-team-member'
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = 'omniauth-github-team-member'
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = OmniAuth::GitHubTeamMember::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'omniauth-github'
|
19
|
+
gem.add_development_dependency 'rspec', '~> 2.7'
|
20
|
+
gem.add_development_dependency 'rack-test'
|
21
|
+
gem.add_development_dependency 'simplecov'
|
22
|
+
gem.add_development_dependency 'webmock'
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OmniAuth::Strategies::GitHub do
|
4
|
+
subject do
|
5
|
+
OmniAuth::Strategies::GitHub.new({})
|
6
|
+
end
|
7
|
+
|
8
|
+
context "client options" do
|
9
|
+
it 'should have correct site' do
|
10
|
+
subject.options.client_options.site.should eq("https://api.github.com")
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should have correct authorize url' do
|
14
|
+
subject.options.client_options.authorize_url.should eq('https://github.com/login/oauth/authorize')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should have correct token url' do
|
18
|
+
subject.options.client_options.token_url.should eq('https://github.com/login/oauth/access_token')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OmniAuth::Strategies::GitHubTeamMember do
|
4
|
+
subject do
|
5
|
+
OmniAuth::Strategies::GitHubTeamMember.new({})
|
6
|
+
end
|
7
|
+
|
8
|
+
context 'client options' do
|
9
|
+
it 'should have correct site' do
|
10
|
+
subject.options.client_options.site.should eq('https://api.github.com')
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should have correct authorize url' do
|
14
|
+
subject.options.client_options.authorize_url.should eq('https://github.com/login/oauth/authorize')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should have correct token url' do
|
18
|
+
subject.options.client_options.token_url.should eq('https://github.com/login/oauth/access_token')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
$:.unshift File.expand_path('..', __FILE__)
|
2
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start
|
5
|
+
require 'rspec'
|
6
|
+
require 'rack/test'
|
7
|
+
require 'webmock/rspec'
|
8
|
+
require 'omniauth'
|
9
|
+
require 'omniauth-github'
|
10
|
+
require 'omniauth-github-team-member'
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.include WebMock::API
|
14
|
+
config.include Rack::Test::Methods
|
15
|
+
config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
|
16
|
+
end
|
17
|
+
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-github-team-member
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jonathan Hoyt
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: omniauth-github
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.7'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.7'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rack-test
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: simplecov
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: webmock
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: OmniAuth strategy for GitHub Team Auth.
|
95
|
+
email:
|
96
|
+
- jonmagic@gmail.com
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files: []
|
100
|
+
files:
|
101
|
+
- .gitignore
|
102
|
+
- .rspec
|
103
|
+
- Gemfile
|
104
|
+
- Guardfile
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- lib/omniauth-github-team-member.rb
|
108
|
+
- lib/omniauth-github-team-member/version.rb
|
109
|
+
- lib/omniauth/strategies/github_team_member.rb
|
110
|
+
- omniauth-github-team-member.gemspec
|
111
|
+
- spec/omniauth/strategies/github_spec.rb
|
112
|
+
- spec/omniauth/strategies/github_team_member_spec.rb
|
113
|
+
- spec/spec_helper.rb
|
114
|
+
homepage: https://github.com/jonmagic/omniauth-github-team-member
|
115
|
+
licenses: []
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 1.8.23
|
135
|
+
signing_key:
|
136
|
+
specification_version: 3
|
137
|
+
summary: OmniAuth strategy for GitHub Team Auth.
|
138
|
+
test_files:
|
139
|
+
- spec/omniauth/strategies/github_spec.rb
|
140
|
+
- spec/omniauth/strategies/github_team_member_spec.rb
|
141
|
+
- spec/spec_helper.rb
|