我想使用FOSOAuthServerBundle提供一个使用OAuth2保护的RESTful API,我不确定我该做什么.
我按照文档中的基本步骤进行操作,但有些东西丢失了,我无法找到我需要的完整示例.
所以,我试着理解这个实现最好的例子(我发现的唯一一个),但仍有一些我不理解的事情.
首先,为什么我们需要API中的登录页面?假设我的客户端是iPhone或Android应用程序,我看到应用程序上登录页面的兴趣,但我认为客户端只需从API调用Web服务来获取其令牌,我错了吗?那么如何通过REST端点实现自动化和令牌提供?
然后,文档告诉写这个防火墙:
oauth_authorize:
pattern: ^/oauth/v2/auth
# Add your favorite authentication process here
Run Code Online (Sandbox Code Playgroud)
我不知道如何添加身份验证过程.我应该自己编写一个,例如在本教程之后还是我完全错了?
在全球范围内,有人可以花时间在文档中的五个步骤之后解释所需的过程,以提供OAuth2安全的RESTful API吗?这将是非常好的......
在@Sehael回答之后编辑:
在它完美之前我还有一些问题......
这里的"客户"代表什么?对于exemaple,我应该为iPhone应用程序创建一个客户端,为Android应用程序创建另一个客户端吗?我是否必须为每个想要使用API的实例创建一个新客户端?在这种情况下,最佳做法是什么?
与您不同,我不会将OAuth流程用于前端网站,而是使用"经典"symfony方式.你觉得这很奇怪,还是正常的?
refresh_token的用处是什么?如何使用它?
我试图测试我的新OAuth受保护服务.我使用支持OAuth 1.0的POSTman chrome扩展,OAuth2看起来像OAuth1足以用POSTman进行测试吗?有一个"秘密令牌"字段,我不知道如何填写.如果我不能,我很高兴看到你的(@Sehael)PHP课程,就像你提出的那样./编辑:好的我觉得我找到了这个答案.我刚刚添加了access_token作为GET参数的令牌作为值.它似乎工作.不幸的是,我必须对bundle代码进行反向engenering才能找到它而不是在文档中读取它.
无论如何,非常感谢!
我正试图找到设计模型中实体之间关系的最佳方法.我会试着清楚地解释一下.
想象一下以下的Doctrine2实体:
class ImageHistory
{
/**
* @var Image
*/
protected $current;
/**
* @var \Doctrine\Common\Collections\Collection
*/
protected $old;
}
class Dog
{
protected $name;
/**
* @var ImageHistory
*/
protected $imageHistory;
}
class Cat
{
protected $name;
/**
* @var ImageHistory
*/
protected $imageHistory;
}
Run Code Online (Sandbox Code Playgroud)
我想建立两个一对多的双向学说关系,Cat并且Dog是关系的拥有方.两个Cat和Dog类都有这个实体配置:
manyToOne:
imageHistory:
targetEntity: ImageHistory
joinColumn:
name: image_history_id
referencedColumnName: id
Run Code Online (Sandbox Code Playgroud)
如何表示te关系的另一面?
oneToMany:
owner:
targetEntity: <What can I write here?>
mappedBy: imageHistory
Run Code Online (Sandbox Code Playgroud)
我想象一个解决方案,其中Cat和Dog继承一个 …
我想做一些看起来像在如何使用数据变换器教程中所做的事情.但我想添加一个过程,我找不到任何例子.
在symfony教程中,数据转换是关于将问题编号更改为Issue对象.这是在reverseTransform()功能中完成的IssueToNumberTransformer
public function reverseTransform($number)
{
if (!$number) {
return null;
}
$issue = $this->om
->getRepository('AcmeTaskBundle:Issue')
->findOneBy(array('number' => $number))
;
if (null === $issue) {
throw new TransformationFailedException(sprintf(
'An issue with number "%s" does not exist!',
$number
));
}
return $issue;
}
Run Code Online (Sandbox Code Playgroud)
我们可以看到,如果提供了无效的问题编号,转换将失败并且函数抛出一个TransformationFailedException.因此,表单作为错误消息"此值无效".个性化这个消息会很棒.
数据转换过程在任何验证之前执行(使用约束应用于字段),因此在尝试转换之前,我找不到验证问题编号的方法.
作为我必须在转换之前验证的另一个例子,我使用MongoDB文档管理器将"问题mongo id"转换为问题(表单由REST API服务器使用,这就是我收到id的原因).所以:
public function reverseTransform($id)
{
if (!$number) {
return null;
}
$issue = $this->dm
->getRepository('AcmeTaskBundle:Issue')
->find(new \MongoId($id))
;
if (null === $issue) {
throw new …Run Code Online (Sandbox Code Playgroud) 我想使用JMSSerializer处理序列化和反序列化的单个对象属性.我们有这个课:
class Task {
const STATUS_PENDING = 0;
const STATUS_OVER = 1;
protected $status;
/* getter and setter */
public function getStatusLabel()
{
return ['pending', 'over'][$this->getStatus()];
}
public static function getStatusFromLabel($label)
{
return [
'pending' => self::STATUS_PENDING,
'over' => self::STATUS_OVER
][$label];
}
}
Run Code Online (Sandbox Code Playgroud)
我想返回Task的实例抛出一个REST API(使用FOSRestBundle).问题是我不想返回$status属性的原始值,而是返回"label"值.
像这样配置我的序列化:
Task:
exclusion_policy: ALL
properties:
status:
expose: true
type: string
Run Code Online (Sandbox Code Playgroud)
JMS Serializer认为原始值为0或1,但我想在序列化对象中发送'pending'或'over'(using getStatusLabel).并且在反序列化(使用getStatusFromLabel)上执行相反的工作.
我认为virtual_properties它只是一个但是它只能用于治疗方向.
我尝试使用这样的自定义处理程序:
class TaskHandler implements SubscribingHandlerInterface
{
public static function getSubscribingMethods()
{
return [
[ …Run Code Online (Sandbox Code Playgroud) 我试图在swagger中描述以下post参数:
{
"sources": [
{
"id": 101,
"parentId": 201
},{
"id": 102,
"parentId": 201
},{
"id": 102,
"parentId": 202
}
],
"destinationId": 301,
"param1": "value 1",
"param2": "value 2",
}
Run Code Online (Sandbox Code Playgroud)
问题是,这sources是一个对象数组,swagger似乎不支持.这是我尝试过的:
paths:
/bulk-action:
post:
parameters:
- name: sources
in: formData
type: array
enum:
$ref: '#/definitions/BulkSource'
- name: destinationId
in: formData
type: integer
- name: param1
in: formData
type: string
- name: param2
in: formData
type: string
definitions:
BulkSource:
type: object
properties:
id:
type: integer
parentId:
type: integer
Run Code Online (Sandbox Code Playgroud)
关于如何解决这个限制的任何想法?
我试图熟悉颤动,并且遇到了一些奇怪的情况。我想建立一个动态ListView的+按钮可以添加元素的地方。我编写了以下状态代码:
class MyWidgetListState extends State<MyWidgetList> {
List<Widget> _objectList = <Widget>[
new Text('test'),
new Text('test')
];
void _addOne() {
setState(() {
_objectList.add(new Text('test'));
});
}
void _removeOne() {
setState(() {
_objectList.removeLast();
});
}
@override
Widget build(BuildContext context) {
return new Column(
children: <Widget>[
new ListView(
shrinkWrap: true,
children: _objectList
),
new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new IconButton(
icon: new Icon(Icons.remove_circle),
iconSize: 36.0,
tooltip: 'Remove',
onPressed: _objectList.length > 2 ? _removeOne : null,
),
new IconButton(
icon: …Run Code Online (Sandbox Code Playgroud) 在 Chrome 扩展程序中,我尝试创建一个动态规则,通过declarativeNetRequest以下方式将字符串附加到用户代理:
chrome.declarativeNetRequest.updateDynamicRules({
addRules: [
{
id: 1,
priority: 1,
action: {
type: 'modifyHeaders' as RuleActionType,
requestHeaders: [
{
header: 'user-agent',
operation: 'append' as HeaderOperation,
value: '-test'
},
],
},
condition: {
regexFilter: 'https://www.yahoo.com\?.*',
resourceTypes: [
'main_frame' as ResourceType,
'sub_frame' as ResourceType,
],
},
},
],
}, async (result: any) => {
console.log('created', result);
});
Run Code Online (Sandbox Code Playgroud)
我在控制台中收到以下错误:
Unchecked runtime.lastError: Rule with id 1 must not specify a request header to be appended.
Run Code Online (Sandbox Code Playgroud)
文档中是否缺少我无法应用append操作的限制requestHeaders?我测试过 …
symfony ×2
dart ×1
doctrine-orm ×1
flutter ×1
forms ×1
oauth-2.0 ×1
oop ×1
php ×1
swagger ×1
swagger-2.0 ×1
validation ×1