omniauth-backstage 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/README.md +11 -0
- data/Rakefile +8 -0
- data/lib/omniauth/backstage/client.rb +16 -0
- data/lib/omniauth/strategies/backstage.rb +37 -0
- data/lib/omniauth-backstage/version.rb +5 -0
- data/lib/omniauth-backstage.rb +2 -0
- data/omniauth-backstage.gemspec +28 -0
- data/spec/omniauth/backstage/client_spec.rb +18 -0
- data/spec/omniauth/strategies/backstage_spec.rb +80 -0
- data/spec/spec_helper.rb +17 -0
- metadata +157 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9df104def5c10cbbbdc3e2c63fbf5c49259e53d8
|
4
|
+
data.tar.gz: ca386cab89dd903c77faf55abec828ca12bafdb4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: be5baccfd1147e73fe934ae6e5f6e6c17effeec0ede8264b7b24f09acb664ba49e4195d989753611fb5ce54f9dd08fba1fe169907e6c9ea5c590362db02852ad
|
7
|
+
data.tar.gz: 9ea870c390ae43e58803fe5c797ad2016e7c998a2f4ef12bbc57b7c22c0ac9c7d0ef30d329182722e8aa4f02c7ec3257957be469a36a15e29afc2bf44ecc4283
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# OmniAuth Backstage
|
2
|
+
|
3
|
+
This is the OmniAuth strategy for authenticating to [Backstage](https://github.com/backstage/backstage).
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
use OmniAuth::Builder do
|
9
|
+
provider :backstage, ENV['BACKSTAGE_CLIENT_ID'], ENV['BACKSTAGE_CLIENT_SECRET'], { site: ENV['BACKSTAGE_SITE'], authorize_url: ENV['BACKSTAGE_AUTHORIZE_URL'], token_url: ENV['BACKSTAGE_TOKEN_URL'] }
|
10
|
+
end
|
11
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module OmniAuth
|
2
|
+
module Backstage
|
3
|
+
class Client
|
4
|
+
def self.client_options(options)
|
5
|
+
ok = %w{site authorize_url token_url}.all? {|param| options.include?(param.to_sym) }
|
6
|
+
raise ArgumentError, 'Missing required parameters.' unless ok
|
7
|
+
|
8
|
+
{
|
9
|
+
site: options[:site],
|
10
|
+
authorize_url: options[:authorize_url],
|
11
|
+
token_url: options[:token_url]
|
12
|
+
}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'omniauth-oauth2'
|
2
|
+
require "omniauth/backstage/client"
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
class Backstage < OmniAuth::Strategies::OAuth2
|
7
|
+
option :name, 'backstage'
|
8
|
+
option :client_options, nil
|
9
|
+
|
10
|
+
uid { raw_info['email'].to_s }
|
11
|
+
|
12
|
+
info do
|
13
|
+
{
|
14
|
+
name: raw_info['name'],
|
15
|
+
email: raw_info['email'],
|
16
|
+
username: raw_info['username']
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
extra do
|
21
|
+
{
|
22
|
+
raw_info: raw_info
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize(app, *args, &block)
|
27
|
+
super(app, *args, &block)
|
28
|
+
options[:client_options] = OmniAuth::Backstage::Client.client_options(options) if options.client_options.nil?
|
29
|
+
end
|
30
|
+
|
31
|
+
def raw_info
|
32
|
+
payload = access_token.get('me').parsed
|
33
|
+
@raw_info ||= payload[:user]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require File.expand_path('../lib/omniauth-backstage/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "omniauth-backstage"
|
6
|
+
spec.version = OmniAuth::Backstage::VERSION
|
7
|
+
spec.license = "MIT"
|
8
|
+
|
9
|
+
spec.authors = ["Alberto Leal"]
|
10
|
+
spec.email = ["albertonb@gmail.com"]
|
11
|
+
spec.description = %q{Backstage OAuth2 Strategy for OmniAuth.}
|
12
|
+
spec.summary = %q{Backstage OAuth2 Strategy for OmniAuth.}
|
13
|
+
spec.homepage = "https://github.com/backstage/omniauth-backstage"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency 'rack-test'
|
23
|
+
spec.add_development_dependency 'rspec', '~> 2.7'
|
24
|
+
spec.add_development_dependency 'simplecov'
|
25
|
+
spec.add_development_dependency 'webmock'
|
26
|
+
|
27
|
+
spec.add_dependency 'omniauth-oauth2', '~> 1.1.2'
|
28
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OmniAuth::Backstage::Client do
|
4
|
+
let(:options) {
|
5
|
+
{
|
6
|
+
site: 'https://backstage.example.org',
|
7
|
+
authorize_url: 'https://backstage.example.org/login/oauth/authorize',
|
8
|
+
token_url: 'https://backstage.example.org/login/oauth/access_token'
|
9
|
+
}
|
10
|
+
}
|
11
|
+
it "raises an exception when missing required params" do
|
12
|
+
expect{ OmniAuth::Backstage::Client.client_options }.to raise_error(ArgumentError)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns client_options struture for omniauth" do
|
16
|
+
expect(OmniAuth::Backstage::Client.client_options(options)).to eq options
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OmniAuth::Strategies::Backstage do
|
4
|
+
let(:access_token) { double('AccessToken', options: {}) }
|
5
|
+
let(:user) { double('User') }
|
6
|
+
let(:parsed_response) { double('Parsed Response', :[] => user) }
|
7
|
+
let(:response) { double('Response', :parsed => parsed_response) }
|
8
|
+
|
9
|
+
let(:backstage) do
|
10
|
+
OmniAuth::Strategies::Backstage.new('CLIENT_ID', 'CLIENT_SECRET',{
|
11
|
+
client_options: {
|
12
|
+
site: 'https://backstage.example.org',
|
13
|
+
authorize_url: 'https://backstage.example.org/login/oauth/authorize',
|
14
|
+
token_url: 'https://backstage.example.org/login/oauth/access_token'
|
15
|
+
}
|
16
|
+
}
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
subject do
|
21
|
+
OmniAuth::Strategies::Backstage.new({})
|
22
|
+
end
|
23
|
+
|
24
|
+
context "client options" do
|
25
|
+
it 'raises an exception if required params are not provided' do
|
26
|
+
expect{ subject }.to raise_error(ArgumentError)
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "initializiation" do
|
30
|
+
it "site endpoint" do
|
31
|
+
expect(backstage.options.client_options.site).to eq('https://backstage.example.org')
|
32
|
+
end
|
33
|
+
|
34
|
+
it "authorize url endpoint" do
|
35
|
+
expect(backstage.options.client_options.authorize_url).to eq('https://backstage.example.org/login/oauth/authorize')
|
36
|
+
end
|
37
|
+
|
38
|
+
it "token endpoint" do
|
39
|
+
expect(backstage.options.client_options.token_url).to eq('https://backstage.example.org/login/oauth/access_token')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "#raw_info" do
|
45
|
+
it "returns user info" do
|
46
|
+
allow(backstage).to receive(:access_token).and_return(access_token)
|
47
|
+
allow(access_token).to receive(:get).with('me').and_return(response)
|
48
|
+
expect(backstage.raw_info).to eq(user)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "info" do
|
53
|
+
before(:each) do
|
54
|
+
backstage.stub(:raw_info).and_return({})
|
55
|
+
end
|
56
|
+
|
57
|
+
it "has name key" do
|
58
|
+
expect(backstage.info).to have_key(:name)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "has email key" do
|
62
|
+
expect(backstage.info).to have_key(:email)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "has username key" do
|
66
|
+
expect(backstage.info).to have_key(:username)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "extra" do
|
71
|
+
it "returns raw user info" do
|
72
|
+
backstage.stub(:raw_info).and_return({ name: 'Alice', username: 'alice', email: 'alice@example.org'})
|
73
|
+
|
74
|
+
expect(backstage.extra).to have_key(:raw_info)
|
75
|
+
%w{name username email}.each do |k|
|
76
|
+
expect(backstage.extra[:raw_info]).to have_key(k.to_sym)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
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
|
+
|
4
|
+
require 'simplecov'
|
5
|
+
SimpleCov.start
|
6
|
+
require 'rspec'
|
7
|
+
require 'rack/test'
|
8
|
+
require 'webmock/rspec'
|
9
|
+
require 'omniauth'
|
10
|
+
require 'omniauth-backstage'
|
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
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-backstage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alberto Leal
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rack-test
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: omniauth-oauth2
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.1.2
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.1.2
|
111
|
+
description: Backstage OAuth2 Strategy for OmniAuth.
|
112
|
+
email:
|
113
|
+
- albertonb@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- Gemfile
|
120
|
+
- README.md
|
121
|
+
- Rakefile
|
122
|
+
- lib/omniauth-backstage.rb
|
123
|
+
- lib/omniauth-backstage/version.rb
|
124
|
+
- lib/omniauth/backstage/client.rb
|
125
|
+
- lib/omniauth/strategies/backstage.rb
|
126
|
+
- omniauth-backstage.gemspec
|
127
|
+
- spec/omniauth/backstage/client_spec.rb
|
128
|
+
- spec/omniauth/strategies/backstage_spec.rb
|
129
|
+
- spec/spec_helper.rb
|
130
|
+
homepage: https://github.com/backstage/omniauth-backstage
|
131
|
+
licenses:
|
132
|
+
- MIT
|
133
|
+
metadata: {}
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
requirements: []
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 2.2.2
|
151
|
+
signing_key:
|
152
|
+
specification_version: 4
|
153
|
+
summary: Backstage OAuth2 Strategy for OmniAuth.
|
154
|
+
test_files:
|
155
|
+
- spec/omniauth/backstage/client_spec.rb
|
156
|
+
- spec/omniauth/strategies/backstage_spec.rb
|
157
|
+
- spec/spec_helper.rb
|