mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-15 14:03:27 +00:00
fix oauth app creation bug
This commit is contained in:
@@ -300,19 +300,18 @@ return call_user_func(function()
|
|||||||
|
|
||||||
if ($submit)
|
if ($submit)
|
||||||
{
|
{
|
||||||
$application = \API_OAuth2_Application::create($app['appbox'], $app['user'], $request->get('name'));
|
$application = \API_OAuth2_Application::create($app['appbox'], $app['user'], $post->getName());
|
||||||
$application->set_description($request->get('description'))
|
$application->set_description($post->getDescription())
|
||||||
->set_redirect_uri($request->get('callback'))
|
->set_redirect_uri($post->getSchemeCallback().$post->getCallback())
|
||||||
->set_type($request->get('type'))
|
->set_type($post->getType())
|
||||||
->set_website($request->get('website'));
|
->set_website($post->getSchemeWebsite().$post->getWebsite());
|
||||||
|
|
||||||
return $app->redirect("/api/oauthv2/applications/dev/" . $application->get_id() . "/show");
|
return $app->redirect("/api/oauthv2/applications/dev/" . $application->get_id() . "/show");
|
||||||
}
|
}
|
||||||
|
|
||||||
$var = array(
|
$var = array(
|
||||||
"violations" => $violations,
|
"violations" => $violations,
|
||||||
"form" => $post,
|
"form" => $post
|
||||||
"request" => $request
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return $app['response']('api/auth/application_dev_new.twig', $var);
|
return $app['response']('api/auth/application_dev_new.twig', $var);
|
||||||
|
@@ -51,6 +51,14 @@ class API_OAuth2_Form_DevAppDesktop
|
|||||||
*/
|
*/
|
||||||
public $callback;
|
public $callback;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $type;
|
||||||
|
public $scheme_website;
|
||||||
|
public $urlwebsite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
@@ -58,10 +66,14 @@ class API_OAuth2_Form_DevAppDesktop
|
|||||||
*/
|
*/
|
||||||
public function __construct(Request $request)
|
public function __construct(Request $request)
|
||||||
{
|
{
|
||||||
$this->name = $request->get('name', null);
|
$this->name = $request->get('name', '');
|
||||||
$this->description = $request->get('description', null);
|
$this->description = $request->get('description', '');
|
||||||
$this->website = $request->get('website', null);
|
$this->scheme_website = $request->get('scheme-website', 'http://');
|
||||||
$this->callback = $request->get('callback', null);
|
$this->website = $request->get('website', '');
|
||||||
|
$this->callback = API_OAuth2_Application::NATIVE_APP_REDIRECT_URI;
|
||||||
|
$this->type = API_OAuth2_Application::DESKTOP_TYPE;
|
||||||
|
|
||||||
|
$this->urlwebsite = $this->scheme_website . $this->website;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -75,18 +87,6 @@ class API_OAuth2_Form_DevAppDesktop
|
|||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param string $callback
|
|
||||||
* @return API_OAuth2_Form_DevApp
|
|
||||||
*/
|
|
||||||
public function setName($name)
|
|
||||||
{
|
|
||||||
$this->name = $name;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
@@ -96,18 +96,6 @@ class API_OAuth2_Form_DevAppDesktop
|
|||||||
return $this->description;
|
return $this->description;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param string $callback
|
|
||||||
* @return API_OAuth2_Form_DevApp
|
|
||||||
*/
|
|
||||||
public function setDescription($description)
|
|
||||||
{
|
|
||||||
$this->description = $description;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
@@ -117,18 +105,6 @@ class API_OAuth2_Form_DevAppDesktop
|
|||||||
return $this->website;
|
return $this->website;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param string $callback
|
|
||||||
* @return API_OAuth2_Form_DevApp
|
|
||||||
*/
|
|
||||||
public function setWebsite($website)
|
|
||||||
{
|
|
||||||
$this->website = $website;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
@@ -140,14 +116,26 @@ class API_OAuth2_Form_DevAppDesktop
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param string $callback
|
* @return string
|
||||||
* @return API_OAuth2_Form_DevApp
|
|
||||||
*/
|
*/
|
||||||
public function setCallback($callback)
|
public function getType()
|
||||||
{
|
{
|
||||||
$this->callback = $callback;
|
return $this->type;
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
public function getSchemeWebsite()
|
||||||
|
{
|
||||||
|
return $this->scheme_website;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUrlwebsite()
|
||||||
|
{
|
||||||
|
return $this->urlwebsite;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSchemeCallback()
|
||||||
|
{
|
||||||
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -162,8 +150,8 @@ class API_OAuth2_Form_DevAppDesktop
|
|||||||
|
|
||||||
$metadata->addPropertyConstraint('name', new Constraints\NotBlank($blank));
|
$metadata->addPropertyConstraint('name', new Constraints\NotBlank($blank));
|
||||||
$metadata->addPropertyConstraint('description', new Constraints\NotBlank($blank));
|
$metadata->addPropertyConstraint('description', new Constraints\NotBlank($blank));
|
||||||
$metadata->addPropertyConstraint('website', new Constraints\NotBlank($blank));
|
$metadata->addPropertyConstraint('urlwebsite', new Constraints\NotBlank($blank));
|
||||||
$metadata->addPropertyConstraint('website', new Constraints\Url($url));
|
$metadata->addPropertyConstraint('urlwebsite', new Constraints\Url($url));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -51,6 +51,12 @@ class API_OAuth2_Form_DevAppInternet
|
|||||||
*/
|
*/
|
||||||
public $callback;
|
public $callback;
|
||||||
|
|
||||||
|
public $scheme_website;
|
||||||
|
public $scheme_callback;
|
||||||
|
|
||||||
|
public $urlwebsite;
|
||||||
|
public $urlcallback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
@@ -58,10 +64,16 @@ class API_OAuth2_Form_DevAppInternet
|
|||||||
*/
|
*/
|
||||||
public function __construct(Request $request)
|
public function __construct(Request $request)
|
||||||
{
|
{
|
||||||
$this->name = $request->get('name', null);
|
$this->name = $request->get('name', '');
|
||||||
$this->description = $request->get('description', null);
|
$this->description = $request->get('description', '');
|
||||||
$this->website = $request->get('website', null);
|
$this->website = $request->get('website', '');
|
||||||
$this->callback = $request->get('callback', null);
|
$this->callback = $request->get('callback', '');
|
||||||
|
$this->scheme_website = $request->get('scheme-website', 'http://');
|
||||||
|
$this->scheme_callback = $request->get('scheme-callback', 'http://');
|
||||||
|
$this->type = API_OAuth2_Application::WEB_TYPE;
|
||||||
|
|
||||||
|
$this->urlwebsite = $this->scheme_website.$this->website;
|
||||||
|
$this->urlcallback = $this->scheme_callback.$this->callback;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -75,18 +87,6 @@ class API_OAuth2_Form_DevAppInternet
|
|||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param string $callback
|
|
||||||
* @return API_OAuth2_Form_DevApp
|
|
||||||
*/
|
|
||||||
public function setName($name)
|
|
||||||
{
|
|
||||||
$this->name = $name;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
@@ -96,18 +96,6 @@ class API_OAuth2_Form_DevAppInternet
|
|||||||
return $this->description;
|
return $this->description;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param string $callback
|
|
||||||
* @return API_OAuth2_Form_DevApp
|
|
||||||
*/
|
|
||||||
public function setDescription($description)
|
|
||||||
{
|
|
||||||
$this->description = $description;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
@@ -117,18 +105,6 @@ class API_OAuth2_Form_DevAppInternet
|
|||||||
return $this->website;
|
return $this->website;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param string $callback
|
|
||||||
* @return API_OAuth2_Form_DevApp
|
|
||||||
*/
|
|
||||||
public function setWebsite($website)
|
|
||||||
{
|
|
||||||
$this->website = $website;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
@@ -140,14 +116,31 @@ class API_OAuth2_Form_DevAppInternet
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param string $callback
|
* @return string
|
||||||
* @return API_OAuth2_Form_DevApp
|
|
||||||
*/
|
*/
|
||||||
public function setCallback($callback)
|
public function getType()
|
||||||
{
|
{
|
||||||
$this->callback = $callback;
|
return $this->type;
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
public function getSchemeWebsite()
|
||||||
|
{
|
||||||
|
return $this->scheme_website;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSchemeCallback()
|
||||||
|
{
|
||||||
|
return $this->scheme_callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUrlwebsite()
|
||||||
|
{
|
||||||
|
return $this->urlwebsite;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUrlcallback()
|
||||||
|
{
|
||||||
|
return $this->urlcallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -162,8 +155,10 @@ class API_OAuth2_Form_DevAppInternet
|
|||||||
|
|
||||||
$metadata->addPropertyConstraint('name', new Constraints\NotBlank($blank));
|
$metadata->addPropertyConstraint('name', new Constraints\NotBlank($blank));
|
||||||
$metadata->addPropertyConstraint('description', new Constraints\NotBlank($blank));
|
$metadata->addPropertyConstraint('description', new Constraints\NotBlank($blank));
|
||||||
$metadata->addPropertyConstraint('website', new Constraints\NotBlank($blank));
|
$metadata->addPropertyConstraint('urlwebsite', new Constraints\NotBlank($blank));
|
||||||
$metadata->addPropertyConstraint('website', new Constraints\Url($url));
|
$metadata->addPropertyConstraint('urlwebsite', new Constraints\Url($url));
|
||||||
|
$metadata->addPropertyConstraint('urlcallback', new Constraints\NotBlank($blank));
|
||||||
|
$metadata->addPropertyConstraint('urlcallback', new Constraints\Url($url));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,13 +1,13 @@
|
|||||||
{% macro input(name, value, violations, type, size) %}
|
{% macro input(name, value, violations, property, type, size) %}
|
||||||
{% if violations is none %}
|
{% if violations is none %}
|
||||||
<input type="{{ type|default('text') }}" name="{{ name }}" value="{{ value|e }}" size="{{ size|default(20) }}" />
|
<input type="{{ type|default('text') }}" name="{{ name }}" value="{{ value|e }}" size="{{ size|default(20) }}" />
|
||||||
{% else %}
|
{% else %}
|
||||||
{% set hasError = "false" %}
|
{% set hasError = "false" %}
|
||||||
{% for violation in violations %}
|
{% for violation in violations %}
|
||||||
{% if violation.getPropertyPath == name and hasError == "false" %}
|
{% if violation.getPropertyPath == property and hasError == "false" %}
|
||||||
{% set hasError = "true" %}
|
{% set hasError = "true" %}
|
||||||
<input type="{{ type|default('text') }}" name="{{ name }}" value="{{ violation.getInvalidValue }}" size="{{ size|default(20) }}" />
|
<input type="{{ type|default('text') }}" name="{{ name }}" value="{{ value }}" size="{{ size|default(20) }}" />
|
||||||
<div style="color:red" > {{violation.getMessage}} </div>
|
<div style="color:red" > {{ violation.getInvalidValue }} - {{violation.getMessage}} </div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if hasError == "false" %}
|
{% if hasError == "false" %}
|
||||||
@@ -15,13 +15,13 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% macro textarea(name, value, violations, rows, cols) %}
|
{% macro textarea(name, value, violations,property, rows, cols) %}
|
||||||
{% if violations is none %}
|
{% if violations is none %}
|
||||||
<textarea name="{{ name }}" rows="{{ rows|default(4)}}" cols="{{cols|default(20)}}" >{{ value|e}}</textarea>
|
<textarea name="{{ name }}" rows="{{ rows|default(4)}}" cols="{{cols|default(20)}}" >{{ value|e}}</textarea>
|
||||||
{% else %}
|
{% else %}
|
||||||
{% set hasError = "false" %}
|
{% set hasError = "false" %}
|
||||||
{% for violation in violations %}
|
{% for violation in violations %}
|
||||||
{% if violation.getPropertyPath == name and hasError == "false" %}
|
{% if violation.getPropertyPath == property and hasError == "false" %}
|
||||||
{% set hasError = "true" %}
|
{% set hasError = "true" %}
|
||||||
<textarea name="{{ name }}" rows="{{ rows|default(4)}}" cols="{{cols|default(20)}}" >{{ violation.getInvalidValue}}</textarea>
|
<textarea name="{{ name }}" rows="{{ rows|default(4)}}" cols="{{cols|default(20)}}" >{{ violation.getInvalidValue}}</textarea>
|
||||||
<div style="color:red" > {{violation.getMessage}} </div>
|
<div style="color:red" > {{violation.getMessage}} </div>
|
||||||
@@ -37,36 +37,48 @@
|
|||||||
<form id="form_create" action="/api/oauthv2/applications/dev/create" method="POST">
|
<form id="form_create" action="/api/oauthv2/applications/dev/create" method="POST">
|
||||||
{% if form is none %}
|
{% if form is none %}
|
||||||
{% set name, description, website, callback = '', '', '', ''%}
|
{% set name, description, website, callback = '', '', '', ''%}
|
||||||
|
{% set app_type = 'web'%}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% set name = form.name %}
|
{% set name = form.name %}
|
||||||
{% set description = form.description %}
|
{% set description = form.description %}
|
||||||
{% set website = form.website %}
|
{% set website = form.website %}
|
||||||
{% set callback = form.callback %}
|
{% set callback = form.callback %}
|
||||||
|
{% set app_type = form.type %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<table id = "app-dev-create">
|
<table id = "app-dev-create">
|
||||||
<tr>
|
<tr>
|
||||||
<td><label for="name">{% trans 'Nom' %}</label></td>
|
<td><label for="name">{% trans 'Nom' %}</label></td>
|
||||||
<td>{{ _self.input("name", name, violations) }}</td>
|
<td>{{ _self.input("name", name, violations, 'name') }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><label for="description">{% trans 'Description' %}</label></td>
|
<td><label for="description">{% trans 'Description' %}</label></td>
|
||||||
<td>{{ _self.textarea("description", description, violations,5,17) }}</td>
|
<td>{{ _self.textarea("description", description, 'description', violations, 5, 17) }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><label for="website">{% trans 'Site web' %}</label></td>
|
<td><label for="website">{% trans 'Site web' %}</label></td>
|
||||||
<td>{{ _self.input("website", website|default("http://"), violations) }}</td>
|
<td class="url-td">
|
||||||
|
<select name="scheme-website">
|
||||||
|
<option value="http://">http://</option>
|
||||||
|
<option value="https://">https://</option>
|
||||||
|
</select>
|
||||||
|
{{ _self.input("website", website, violations, 'urlwebsite') }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><label for="type">{% trans 'Type d\'application' %}</label></td>
|
<td><label for="type">{% trans 'Type d\'application' %}</label></td>
|
||||||
<td>{% trans 'Application web' %}
|
<td>{% trans 'Application web' %}
|
||||||
<input type="radio" name="type" value="web" {{ request.get("type") == "web" ? "checked='checked'" : "" }}/>
|
<input type="radio" name="type" value="web" {{ app_type == "web" ? "checked='checked'" : "" }}/>
|
||||||
{% trans 'Application desktop' %}
|
{% trans 'Application desktop' %}
|
||||||
<input type="radio" name="type" value="desktop" {{ request.get("type") == "desktop" ? "checked='checked'" : "" }}/></td>
|
<input type="radio" name="type" value="desktop" {{ app_type == "desktop" ? "checked='checked'" : "" }}/></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% if request.get("type") == "web" %}
|
{% if app_type == "web" %}
|
||||||
<tr class="callback" style="height:25px;">
|
<tr class="callback" style="height:25px;">
|
||||||
<td><label for="callback">{% trans 'URL de callback' %} <br/></label></td>
|
<td><label for="callback">{% trans 'URL de callback' %} <br/></label></td>
|
||||||
<td>{{ _self.input("callback", callback|default("http://"), violations) }}</td>
|
<td class="url-td">
|
||||||
|
<select name="scheme-callback">
|
||||||
|
<option value="http://">http://</option>
|
||||||
|
<option value="https://">https://</option>
|
||||||
|
</select>
|
||||||
|
{{ _self.input("callback", callback, violations, 'urlcallback') }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<tr>
|
<tr>
|
||||||
|
@@ -25,7 +25,16 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>{% trans 'URL de callback' %}</td>
|
<td>{% trans 'URL de callback' %}</td>
|
||||||
<td class="url_callback"><span class="url_callback_input">{{app.get_redirect_uri}}</span> <button type="button" class="save_callback" style="display:none;">save</button><button type="button" class="modifier_callback" style="display:none;">modifier</button></td>
|
{% if app.get_type == constant('API_OAuth2_Application::DESKTOP_TYPE') %}
|
||||||
|
<td>
|
||||||
|
<span>{{app.get_redirect_uri}}</span>
|
||||||
|
</td>
|
||||||
|
{% else %}
|
||||||
|
<td class="url_callback"><span class="url_callback_input">{{app.get_redirect_uri}}</span>
|
||||||
|
<button type="button" class="save_callback" style="display:none;">save</button>
|
||||||
|
<button type="button" class="modifier_callback" style="display:none;">modifier</button>
|
||||||
|
</td>
|
||||||
|
{%endif%}
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Authorize endpoint</td>
|
<td>Authorize endpoint</td>
|
||||||
|
@@ -332,8 +332,9 @@
|
|||||||
width:100%;
|
width:100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
#app-dev-create td input[type=text], #app-dev-create td textarea{
|
#app-dev-create td input[type=text], #app-dev-create td textarea, #app-dev-create td select{
|
||||||
width:100%;
|
display:inline-block;
|
||||||
|
width:95%;
|
||||||
border: 1px solid #CCCCCC;
|
border: 1px solid #CCCCCC;
|
||||||
border-radius: 4px 4px 4px 4px;
|
border-radius: 4px 4px 4px 4px;
|
||||||
box-shadow: 0 1px 1px #EEEEEE;
|
box-shadow: 0 1px 1px #EEEEEE;
|
||||||
@@ -341,6 +342,14 @@
|
|||||||
padding: 6px;
|
padding: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#app-dev-create td input[name=callback], #app-dev-create td input[name=website]{
|
||||||
|
width:85%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#app-dev-create .url-td select{
|
||||||
|
width:12%;
|
||||||
|
}
|
||||||
|
|
||||||
#app-dev-create td{
|
#app-dev-create td{
|
||||||
text-align:left;
|
text-align:left;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user