-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 tsov/assertion
Added Assertion Flow
- Loading branch information
Showing
13 changed files
with
157 additions
and
6 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
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
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,25 @@ | ||
module Doorkeeper | ||
module Request | ||
class Assertion | ||
def self.build(server) | ||
new(server.client, server.resource_owner_from_assertion, server) | ||
end | ||
|
||
attr_accessor :client, :resource_owner, :server | ||
|
||
def initialize(client, resource_owner, server) | ||
@client, @resource_owner, @server = client, resource_owner, server | ||
end | ||
|
||
def request | ||
# TODO: For now OAuth::PasswordAccessTokenRequest is reused for the Assertion Flow. In need of | ||
# OAuth::AssertionAccessTokenRequest in future | ||
@request ||= OAuth::PasswordAccessTokenRequest.new(Doorkeeper.configuration, client, resource_owner, server.parameters) | ||
end | ||
|
||
def authorize | ||
request.authorize | ||
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
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
5 changes: 5 additions & 0 deletions
5
spec/dummy/db/migrate/20130624151512_add_assertion_to_users.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddAssertionToUsers < ActiveRecord::Migration | ||
def change | ||
add_column :users, :assertion, :string | ||
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
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,74 @@ | ||
# coding: utf-8 | ||
|
||
require 'spec_helper_integration' | ||
|
||
feature 'Resource Owner Assertion Flow inproperly set up' do | ||
background do | ||
client_exists | ||
create_resource_owner | ||
end | ||
|
||
context 'with valid user assertion' do | ||
scenario "should not issue new token" do | ||
expect { | ||
post assertion_endpoint_url(:client => @client, :resource_owner => @resource_owner) | ||
}.to_not change { Doorkeeper::AccessToken.count } | ||
end | ||
end | ||
end | ||
|
||
feature 'Resource Owner Assertion Flow' do | ||
background do | ||
config_is_set(:resource_owner_from_assertion) { User.where(:assertion => params[:assertion]).first } | ||
client_exists | ||
create_resource_owner | ||
end | ||
|
||
context 'with valid user assertion' do | ||
scenario "should issue new token" do | ||
expect { | ||
post assertion_endpoint_url(:client => @client, :resource_owner => @resource_owner) | ||
}.to change { Doorkeeper::AccessToken.count }.by(1) | ||
|
||
token = Doorkeeper::AccessToken.first | ||
|
||
should_have_json 'access_token', token.token | ||
end | ||
|
||
scenario "should issue a refresh token if enabled" do | ||
config_is_set(:refresh_token_enabled, true) | ||
|
||
post assertion_endpoint_url(:client => @client, :resource_owner => @resource_owner) | ||
|
||
token = Doorkeeper::AccessToken.first | ||
|
||
should_have_json 'refresh_token', token.refresh_token | ||
end | ||
|
||
scenario 'should return the same token if it is still accessible' do | ||
client_is_authorized(@client, @resource_owner) | ||
|
||
post assertion_endpoint_url(:client => @client, :resource_owner => @resource_owner) | ||
|
||
Doorkeeper::AccessToken.count.should be(1) | ||
|
||
should_have_json 'access_token', Doorkeeper::AccessToken.first.token | ||
end | ||
|
||
end | ||
|
||
context "with invalid user assertion" do | ||
scenario "should not issue new token with bad assertion" do | ||
expect { | ||
post assertion_endpoint_url( :client => @client, :assertion => 'i_dont_exist' ) | ||
}.to_not change { Doorkeeper::AccessToken.count } | ||
end | ||
|
||
scenario "should not issue new token without assertion" do | ||
expect { | ||
post assertion_endpoint_url( :client => @client ) | ||
}.to_not change { Doorkeeper::AccessToken.count } | ||
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
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