-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Takes Rack::Request - Authenticates client - Builds, saves and returns token
- Loading branch information
1 parent
d16df7d
commit 59979d2
Showing
16 changed files
with
160 additions
and
28 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,4 @@ | ||
require 'oauth2_server/bearer_token/authenticator' | ||
require 'oauth2_server/bearer_token/authentication_header_builder' | ||
require 'oauth2_server/bearer_token/token_builder' | ||
require 'oauth2_server/bearer_token/builder' | ||
require 'oauth2_server/bearer_token/dealer' |
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,6 @@ | ||
require 'oauth2_server/bearer_token/builder/base' | ||
require 'oauth2_server/bearer_token/builder/client_credentials' | ||
require 'oauth2_server/bearer_token/builder/password' | ||
require 'oauth2_server/bearer_token/builder/authorization_code' | ||
require 'oauth2_server/bearer_token/builder/refresh_token' | ||
require 'oauth2_server/bearer_token/builder/factory' |
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
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
2 changes: 1 addition & 1 deletion
2
...token/token_builder/client_credentials.rb → ...earer_token/builder/client_credentials.rb
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
6 changes: 3 additions & 3 deletions
6
...ver/bearer_token/token_builder/factory.rb → ...h2_server/bearer_token/builder/factory.rb
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
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
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
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 @@ | ||
module Oauth2Server | ||
module BearerToken | ||
class Dealer | ||
def initialize(request, options = {}) | ||
@request = request | ||
@options = options | ||
end | ||
|
||
def token | ||
@_token ||= begin | ||
save_token | ||
built_token | ||
end | ||
end | ||
|
||
alias_method :deal!, :token | ||
|
||
private | ||
attr_reader :request, :options | ||
|
||
def save_token | ||
token_repositories.each do |repository| | ||
repository.save_token(built_token) | ||
end | ||
end | ||
|
||
def token_repositories | ||
if options.has_key?(:token_repository) | ||
Array(options[:token_repository]) | ||
elsif options.has_key?(:token_repositories) | ||
options[:token_repositories] | ||
elsif options.has_key?(:configuration) | ||
options[:configuration].registered_token_repositories | ||
else | ||
Oauth2Server.configuration.registered_token_repositories | ||
end | ||
end | ||
|
||
def built_token | ||
@_built_token ||= token_builder.token | ||
end | ||
|
||
def token_builder | ||
token_builder_factory.builder | ||
end | ||
|
||
def token_builder_factory | ||
Builder::Factory.new(client, request, options) | ||
end | ||
|
||
def client | ||
client_authenticator.client | ||
end | ||
|
||
def client_authenticator | ||
ClientAuthenticator.new(request, options) | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
.../token_builder/authorization_code_spec.rb → ..._token/builder/authorization_code_spec.rb
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
2 changes: 1 addition & 1 deletion
2
.../token_builder/client_credentials_spec.rb → ..._token/builder/client_credentials_spec.rb
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
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
2 changes: 1 addition & 1 deletion
2
...arer_token/token_builder/password_spec.rb → ...ver/bearer_token/builder/password_spec.rb
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
2 changes: 1 addition & 1 deletion
2
...token/token_builder/refresh_token_spec.rb → ...earer_token/builder/refresh_token_spec.rb
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
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,71 @@ | ||
require 'spec_helper' | ||
|
||
describe Oauth2Server::BearerToken::Dealer do | ||
subject(:dealer) { described_class.new(request, options) } | ||
let(:request) { Rack::Request.new(env) } | ||
let(:env) { Rack::MockRequest.env_for('/') } | ||
let(:client_authenticator) { stub('ClientAuthenticator', client: client) } | ||
let(:client) { FactoryGirl.build(:client) } | ||
let(:builder_factory) { stub('BuilderFactory', builder: builder) } | ||
let(:builder) { stub('Builder', token: token) } | ||
let(:token) { FactoryGirl.build(:token) } | ||
let(:token_repository) { stub('TokenRepository') } | ||
|
||
before do | ||
Oauth2Server::ClientAuthenticator.stub(:new). | ||
with(request, options) { client_authenticator } | ||
Oauth2Server::BearerToken::Builder::Factory.stub(:new). | ||
with(client, request, options) { builder_factory } | ||
token_repository.stub(:save_token).with(token) | ||
end | ||
|
||
shared_examples_for 'deals tokens' do | ||
[:deal!, :token].each do |method| | ||
describe "##{method}" do | ||
it 'saves created token to repository' do | ||
token_repository.should_receive(:save_token).with(token) | ||
dealer.public_send(method) | ||
end | ||
|
||
it 'returns created token' do | ||
expect(dealer.public_send(method)).to eql(token) | ||
end | ||
end | ||
end | ||
end | ||
|
||
context 'when token_repository given' do | ||
let(:options) { {token_repository: token_repository} } | ||
|
||
it_behaves_like 'deals tokens' | ||
end | ||
|
||
context 'when an array of token repositories given' do | ||
let(:options) { {token_repositories: [token_repository]} } | ||
|
||
it_behaves_like 'deals tokens' | ||
end | ||
|
||
context 'when configuration given' do | ||
let(:options) { {configuration: configuration} } | ||
let(:configuration) { Oauth2Server::Configuration.new } | ||
|
||
before do | ||
configuration.register_token_repository(token_repository) | ||
end | ||
|
||
it_behaves_like 'deals tokens' | ||
end | ||
|
||
context 'when given no configuration' do | ||
let(:options) { {} } | ||
let(:configuration) { Oauth2Server::Configuration.new } | ||
|
||
before do | ||
configuration.register_token_repository(token_repository) | ||
Oauth2Server.stub(:configuration) { configuration } | ||
end | ||
|
||
it_behaves_like 'deals tokens' | ||
end | ||
end |