diff --git a/Gemfile b/Gemfile index 052aaa7bc..8b387281c 100644 --- a/Gemfile +++ b/Gemfile @@ -119,6 +119,6 @@ group :test do gem 'rspec-instafail', '>= 0.1.7', :require => false gem 'fuubar' - gem 'diaspora-client', :git => 'git://github.com/diaspora/diaspora-client.git' + gem 'diaspora-client', :path => '~/workspace/diaspora-client' #:git => 'git://github.com/diaspora/diaspora-client.git' end diff --git a/Gemfile.lock b/Gemfile.lock index 1e8a31b37..3bcf03592 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -29,17 +29,6 @@ GIT acts-as-taggable-on (2.0.6) rails (>= 3.0) -GIT - remote: git://github.com/diaspora/diaspora-client.git - revision: 9dc2c29495c7bf040ceceecdf88800f4c91f870c - specs: - diaspora-client (0.0.0) - activerecord - faraday - jwt (>= 0.1.3) - oauth2 - sinatra - GIT remote: git://github.com/iain/http_accept_language.git revision: 0b78aa7849fc90cf9e12586af162fa4c408a795d @@ -63,6 +52,16 @@ GIT jwt (0.1.3) json (>= 1.2.4) +PATH + remote: ~/workspace/diaspora-client + specs: + diaspora-client (0.0.0) + activerecord + faraday + jwt (>= 0.1.3) + oauth2 + sinatra + GEM remote: http://rubygems.org/ specs: diff --git a/app/controllers/authorizations_controller.rb b/app/controllers/authorizations_controller.rb index 902d22c0a..b8153eb45 100644 --- a/app/controllers/authorizations_controller.rb +++ b/app/controllers/authorizations_controller.rb @@ -11,7 +11,11 @@ class AuthorizationsController < ApplicationController def new @requested_scopes = params["scope"].split(',') @client = oauth2_authorization_request.client - #render :layout => "popup" if params[:popup] + + if current_user.applications.present? + tokens = current_user.authorizations.first.access_tokens.first + redirect_to "#{params[:redirect_uri]}&access_token=#{tokens.access_token}&refresh_token=#{tokens.refresh_token}" + end end def create diff --git a/features/oauth.feature b/features/oauth.feature index 1886e8843..92dba9a73 100644 --- a/features/oauth.feature +++ b/features/oauth.feature @@ -16,12 +16,21 @@ Feature: oauth And I should see my "profile.birthday" And I should see my "name" + Scenario: Signup+login (Diaspora Connect) with Chubbies + When I visit "/reset" on Chubbies + And I should have 0 user on Chubbies + And I try to authorize Chubbies + And I press "Authorize" + Then I should be on "/account" on Chubbies + + And I should have 1 user on Chubbies + Scenario: Not authorize Chubbies When I try to authorize Chubbies When I press "No" Then I should be on "/account" on Chubbies - Then I should see "No access token." + And I should have 0 user on Chubbies Scenario: Authorize Chubbies when Chubbies is already connected Given Chubbies is registered on my pod @@ -80,16 +89,18 @@ Feature: oauth Scenario: Login in with Chubbies when you already authorized it Given Chubbies is registered on my pod + And I should have 0 user on Chubbies + When I try to authorize 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" + And I should have 1 user on Chubbies Then I visit "/new" on Chubbies - And I fill in "Diaspora Handle" with "#{@me.diaspora_handle}" + And I fill in my Diaspora ID to connect And I press "Connect to Diaspora" - And I debug Then I should be on "/account" on Chubbies + And I should have 1 user on Chubbies + diff --git a/features/step_definitions/oauth_steps.rb b/features/step_definitions/oauth_steps.rb index a6ebdbdbc..1a50afb69 100644 --- a/features/step_definitions/oauth_steps.rb +++ b/features/step_definitions/oauth_steps.rb @@ -35,7 +35,7 @@ When /^I try to authorize Chubbies$/ do # as we are clearing the Diaspora DB every scenario Then 'I visit "/new" on Chubbies' ### - And "I fill in \"Diaspora Handle\" with \"#{@me.diaspora_handle}\"" + And "I fill in my Diaspora ID to connect" And 'I press "Connect to Diaspora"' Then 'I should be on the new user session page' And "I fill in \"Username\" with \"#{@me.username}\"" @@ -46,8 +46,16 @@ When /^I try to authorize Chubbies$/ do And 'I should see "The best way to chub."' end -When /^I visit "([^"]+)" on Chubbies$/ do |path| +And /^I fill in my Diaspora ID to connect$/ do + And "I fill in \"Diaspora Handle\" with \"#{@me.diaspora_handle}\"" +end +And /^I should have (\d) user on Chubbies$/ do |num| + When "I visit \"/user_count\" on Chubbies" + Then "I should see \"#{num}\"" +end + +When /^I visit "([^"]+)" on Chubbies$/ do |path| former_host = Capybara.app_host Capybara.app_host = "localhost:#{Chubbies::PORT}" visit(path) diff --git a/spec/chubbies/app.rb b/spec/chubbies/app.rb index e1233408f..399d024cb 100644 --- a/spec/chubbies/app.rb +++ b/spec/chubbies/app.rb @@ -31,6 +31,7 @@ module Chubbies end add_index :access_tokens, :user_id, :unique => true create_table :users do |t| + t.string :username, :limit => 127 t.timestamps end end @@ -60,7 +61,7 @@ module Chubbies class App < DiasporaClient::App def current_user - User.first + @user = User.first end def redirect_path @@ -71,6 +72,13 @@ module Chubbies '/account?id=1' end + def account_const + User + end + def create_account(*args) + account_const.create(args) + end + get '/account' do if params['id'] && user = User.where(:id => params['id']).first if user.access_token @@ -89,7 +97,6 @@ module Chubbies end get '/new' do - @user = User.create haml :home end @@ -104,5 +111,9 @@ module Chubbies post '/register' do DiasporaClient::ResourceServer.create!(params) end + + get '/user_count' do + User.count.to_s + end end end