-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from doomspork/implementation
Implementation of PG&E strategy
- Loading branch information
Showing
6 changed files
with
115 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
language: ruby | ||
rvm: | ||
- 2.2.2 | ||
- 2.1.1 | ||
- 2.0.0 | ||
- ruby-head | ||
script: bundle exec rspec | ||
matrix: | ||
allow_failures: | ||
- rvm: ruby-head |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'omniauth-oauth2' | ||
|
||
module OmniAuth | ||
module Strategies | ||
class PGE < OmniAuth::Strategies::OAuth2 | ||
option :client_options, { | ||
site: 'https://api.pge.com', | ||
authorize_url: 'https://api.pge.com/datacustodian/test/oauth/v2/authorize', | ||
token_url: 'https://api.pge.com/datacustodian/test/oauth/v2/token' | ||
} | ||
|
||
def request_phase | ||
super | ||
end | ||
|
||
def authorize_params | ||
super.tap do |params| | ||
%w[scope client_options].each do |v| | ||
if request.params[v] | ||
params[v.to_sym] = request.params[v] | ||
end | ||
end | ||
end | ||
end | ||
|
||
uid { raw_info['id'].to_s } | ||
|
||
info do | ||
end | ||
end | ||
end | ||
end | ||
|
||
OmniAuth.config.add_camelization 'pge', 'PGE' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,20 +9,22 @@ Gem::Specification.new do |spec| | |
spec.authors = ['Sean Callan'] | ||
spec.email = ['[email protected]'] | ||
|
||
spec.summary = %q{OmniAuth strategy for PG&E.} | ||
spec.summary = 'OmniAuth strategy for PG&E.' | ||
spec.homepage = 'https://github.com/doomspork/omniauth-pge' | ||
spec.license = 'MIT' | ||
|
||
spec.files = `git ls-files -z`.split("\x0") | ||
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } | ||
spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) | ||
spec.require_paths = ['lib'] | ||
|
||
spec.add_runtime_dependency 'omniauth-oauth2', '~> 1.3' | ||
|
||
spec.add_development_dependency 'bundler', '~> 1.9' | ||
spec.add_development_dependency 'rake', '~> 10.0' | ||
spec.add_dependency 'omniauth-oauth2', '~> 1.3' | ||
|
||
spec.add_development_dependency 'bundler', '> 1.7' | ||
spec.add_development_dependency 'coveralls', '~> 0.8' | ||
spec.add_development_dependency 'rack-test', '~> 0.6.3' | ||
spec.add_development_dependency 'rake', '~> 10.0' | ||
spec.add_development_dependency 'rspec', '~> 3.2' | ||
spec.add_development_dependency 'simplecov', '~> 0.10' | ||
spec.add_development_dependency 'webmock', '~> 1.21' | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
require 'spec_helper' | ||
|
||
module OmniAuth | ||
module Strategies | ||
describe PGE do | ||
let(:access_token) { stub('AccessToken', options: {}) } | ||
let(:parsed_response) { stub('ParsedResponse') } | ||
let(:response) { stub('Response', parsed: parsed_response) } | ||
|
||
let(:production_site) { 'https://some.other.site.com/api/v3' } | ||
let(:production_authorize_url) { 'https://some.other.site.com/login/oauth/authorize' } | ||
let(:production_token_url) { 'https://some.other.site.com/login/oauth/access_token' } | ||
let(:production) do | ||
OmniAuth::Strategies::PGE.new('PGE_KEY', 'PGE_SECRET', { | ||
client_options: { | ||
site: production_site, | ||
authorize_url: production_authorize_url, | ||
token_url: production_token_url | ||
} | ||
}) | ||
end | ||
|
||
subject do | ||
OmniAuth::Strategies::PGE.new({}) | ||
end | ||
|
||
before(:each) do | ||
allow(subject).to receive(:access_token) { access_token } | ||
end | ||
|
||
context 'client options' do | ||
it 'should have correct site' do | ||
expect(subject.options.client_options.site).to eq 'https://api.pge.com' | ||
end | ||
|
||
it 'should have correct authorize url' do | ||
expect(subject.options.client_options.authorize_url).to eq 'https://api.pge.com/datacustodian/test/oauth/v2/authorize' | ||
end | ||
|
||
it 'should have correct token url' do | ||
expect(subject.options.client_options.token_url).to eq 'https://api.pge.com/datacustodian/test/oauth/v2/token' | ||
end | ||
|
||
describe 'should be overrideable' do | ||
it 'for site' do | ||
expect(production.options.client_options.site).to eq production_site | ||
end | ||
|
||
it 'for authorize url' do | ||
expect(production.options.client_options.authorize_url).to eq production_authorize_url | ||
end | ||
|
||
it 'for token url' do | ||
expect(production.options.client_options.token_url).to eq production_token_url | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters