Chubbies now sends manifest data to create a client

This commit is contained in:
danielgrippi 2011-06-02 16:28:03 -07:00 committed by Maxwell Salzberg
parent e121b0fe6d
commit 01edfeee03
8 changed files with 68 additions and 17 deletions

View file

@ -18,16 +18,14 @@ class AuthorizationsController < ApplicationController
end
def token
if(params[:type] == 'client_associate' && params[:redirect_uri] && params[:name])
client = OAuth2::Provider.client_class.create!(:name => params[:name])
if(params[:type] == 'client_associate' && params[:manifest_url])
client = OAuth2::Provider.client_class.create_from_manifest!(params[:manifest_url])
render :json => {:client_id => client.oauth_identifier,
:client_secret => client.oauth_secret,
:expires_in => 0,
:flows_supported => "",
:user_endpoint_url => "bob"}
#redirect_to("#{params[:redirect_uri]}?#{query_string}")
}
else
render :text => "bad request", :status => 403
@ -35,3 +33,10 @@ class AuthorizationsController < ApplicationController
end
end
OAuth2::Provider.client_class.instance_eval do
def self.create_from_manifest! manifest_url
puts manifest_url
manifest = JSON.parse(RestClient.get(manifest_url).body)
create!(manifest)
end
end

View file

@ -1,7 +1,24 @@
%br
%br
.prepend-4
.floating.span-15
.span-3.append-1
= image_tag(@client.icon_url, :id => 'client-application-image')
.span-10
= form_for :authorization,
:url => oauth_authorize_path(params.slice(:redirect_uri, :client_id, :client_secret)) do |form|
%h2
%h1
= "Authorize #{@client.name}?"
.description
= @client.description
%br
%p
= form.submit "Fuck Yeah!", :value => "Yes"
= form.submit "Hell No.", :value => "No"

View file

@ -0,0 +1,13 @@
class DiasporaOAuthClientFields < ActiveRecord::Migration
def self.up
add_column :oauth_clients, :description, :text
add_column :oauth_clients, :homepage_url, :string
add_column :oauth_clients, :icon_url, :string
end
def self.down
remove_column :oauth_clients, :icon_url
remove_column :oauth_clients, :homepage_url
remove_column :oauth_clients, :description
end
end

View file

@ -225,6 +225,9 @@ ActiveRecord::Schema.define(:version => 20110603212633) do
t.string "name"
t.string "oauth_identifier", :limit => 32, :null => false
t.string "oauth_secret", :limit => 32, :null => false
t.text "description"
t.string "homepage_url"
t.string "icon_url"
end
create_table "people", :force => true do |t|

View file

@ -10,6 +10,7 @@ Feature: oauth
When I visit "/" on Chubbies
And I try to authorize Chubbies
Then I should see "Authorize Chubbies?"
And I should see "Chubbies tests Diaspora's OAuth capabilities."
When I press "Yes"
Then I should be on "/account" on Chubbies
@ -20,6 +21,7 @@ Feature: oauth
When I visit "/" on Chubbies
And I try to authorize Chubbies
Then I should see "Authorize Chubbies?"
And I should see "Chubbies tests Diaspora's OAuth capabilities."
When I press "No"
Then I should be on "/callback" on Chubbies
@ -30,6 +32,7 @@ Feature: oauth
When I visit "/" on Chubbies
And I try to authorize Chubbies
Then I should see "Authorize Chubbies?"
And I should see "Chubbies tests Diaspora's OAuth capabilities."
When I press "Yes"
Then I should be on "/account" on Chubbies

View file

@ -2926,3 +2926,6 @@ h1.tag
#facebox
input[type='text'], input.text
:width 98%
#client-application-image
:max-width 100%

View file

@ -80,8 +80,7 @@ get '/account' do
if !@@client_id && !@@client_secret
response = HTTParty.post(token_url, :body => {
:type => :client_associate,
:name => :Chubbies,
:redirect_uri => redirect_uri
:manifest_url => "http://" + request.host_with_port + "/manifest"
})
json = JSON.parse(response.body)
@ -90,7 +89,6 @@ get '/account' do
@@client_secret = json["client_secret"]
redirect '/account'
else
if access_token
@resource_response = get_with_access_token("/api/v0/me")
@ -101,6 +99,15 @@ get '/account' do
end
end
get '/manifest' do
{
:name => "Chubbies",
:description => "Chubbies tests Diaspora's OAuth capabilities.",
:homepage_url => "http://" + request.host_with_port,
:icon_url => "http://" + request.host_with_port + "/chubbies.jpeg"
}.to_json
end
get '/reset' do
@@client_id = nil
@@client_secret = nil

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 KiB