Skip to content
Extraits de code Groupes Projets
Valider 01edfeee rédigé par danielgrippi's avatar danielgrippi Validation de Maxwell Salzberg
Parcourir les fichiers

Chubbies now sends manifest data to create a client

parent e121b0fe
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -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}")
:client_secret => client.oauth_secret,
:expires_in => 0,
:flows_supported => "",
}
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
= form_for :authorization,
:url => oauth_authorize_path(params.slice(:redirect_uri, :client_id, :client_secret)) do |form|
%h2
= "Authorize #{@client.name}?"
= form.submit "Fuck Yeah!", :value => "Yes"
= form.submit "Hell No.", :value => "No"
%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|
%h1
= "Authorize #{@client.name}?"
.description
= @client.description
%br
%p
= form.submit "Fuck Yeah!", :value => "Yes"
= form.submit "Hell No.", :value => "No"
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
......@@ -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|
......
......@@ -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
......
......@@ -2926,3 +2926,6 @@ h1.tag
#facebox
input[type='text'], input.text
:width 98%
#client-application-image
:max-width 100%
......@@ -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
......
spec/support/chubbies/public/chubbies.jpeg

147 ko

0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter