added authorizations page where a user can see all of their authorized applications

This commit is contained in:
Ilya Zhitomirskiy 2011-06-13 15:40:55 -07:00
parent f31a78f23f
commit 3d77186d35
6 changed files with 27 additions and 12 deletions

View file

@ -1,7 +1,7 @@
class AuthorizationsController < ApplicationController
include OAuth2::Provider::Rack::AuthorizationCodesSupport
before_filter :authenticate_user!, :except => :token
before_filter :block_invalid_authorization_code_requests, :except => :token
before_filter :block_invalid_authorization_code_requests, :except => [:token, :index]
skip_before_filter :verify_authenticity_token, :only => :token
@ -33,6 +33,11 @@ class AuthorizationsController < ApplicationController
render :text => "bad request", :status => 403
end
end
def index
@authorizations = current_user.authorizations
@applications = current_user.applications
end
end
OAuth2::Provider.client_class.instance_eval do

View file

@ -40,6 +40,9 @@ class User < ActiveRecord::Base
has_many :services
has_many :user_preferences
has_many :authorizations, :class_name => 'OAuth2::Provider::Models::ActiveRecord::Authorization', :foreign_key => :resource_owner_id
has_many :applications, :through => :authorizations, :source => :client
before_save do
person.save if person && person.changed?
end

View file

@ -10,6 +10,7 @@ en:
profile: "Profile"
account: "Account"
_services: "Services"
_applications: "Applications"
_photos: "photos"
ok: "OK"
cancel: "Cancel"

View file

@ -68,10 +68,6 @@ Diaspora::Application.routes.draw do
resources :photos, :controller => "photos", :only => [:create, :show, :destroy]
end
get "/oauth/authorize" => "authorizations#new"
post "/oauth/authorize" => "authorizations#create"
post "/oauth/token" => "authorizations#token"
#Temporary token_authenticable route
resource :token, :only => [:show, :create]
@ -119,6 +115,13 @@ Diaspora::Application.routes.draw do
# External
get "/oauth/authorize" => "authorizations#new"
post "/oauth/authorize" => "authorizations#create"
post "/oauth/token" => "authorizations#token"
resources :authorizations, :only => [:index]
resources :services, :only => [:index, :destroy]
controller :services do
match '/auth/:provider/callback' => :create

View file

@ -10,8 +10,6 @@ Feature: oauth
Scenario: Authorize Chubbies
When I try to authorize Chubbies
Then I should see "Chubbies"
And I should see "The best way to chub."
When I press "Authorize"
Then I should be on "/account" on Chubbies
@ -20,22 +18,25 @@ Feature: oauth
Scenario: Not authorize Chubbies
When I try to authorize Chubbies
Then I should see "Chubbies"
And I should see "The best way to chub."
When I press "No"
Then I should be on "/account" on Chubbies
Then I should see "No access token."
Scenario: Authorize Chubbies
Scenario: Authorize Chubbies when Chubbies is already registeded
Given Chubbies is registered on my pod
When I try to authorize Chubbies
Then I should see "Chubbies"
And I should see "The best way to chub."
And there is only one Chubbies
When I press "Authorize"
Then I should be on "/account" on Chubbies
And I should see my "profile.birthday"
And I should see my "name"
Scenario: Authorize Chubbies should place it on the authorized applications page
When I try to authorize Chubbies
When I press "Authorize"
And I am on the authorizations page
Then I should see "Chubbies"
And I should see "The best way to chub."

View file

@ -34,6 +34,8 @@ When /^I try to authorize Chubbies$/ do
And "I fill in \"Password\" with \"#{@me.password}\""
And 'I press "Sign in"'
Then 'I should be on the oauth authorize page'
Then 'I should see "Chubbies"'
And 'I should see "The best way to chub."'
end
When /^I visit "([^"]+)" on Chubbies$/ do |path|