I'm trying to implement async HTTP client with Symfony and amphp/http-client, in symfony docs said thatto enable it for HTTP I need to add http_version: '2.0'option to config and I did it:
framework:
http_client:
http_version: '2.0'
scoped_clients:
site:
base_uri: '%env(URL)%'
headers:
x-access-token: '%env(ACCESS_TOKEN)%'
but it's not working and I'm getting error Unrecognized option "http_version" under "framework.http_client". Available options are "default_options", "enabled", "max_host_connections", "mock_response_factory", "scoped_clients".
Any idea what is wrong?? Thanks in advance!
Looks like the docs might need to be updated a bit. Under a 5.2 app:
bin/console config:dump-reference framework http_client
# HTTP Client configuration
http_client:
enabled: true
# The maximum number of connections to a single host.
max_host_connections: ~
default_options:
# Associative array: header => value(s).
headers:
# Prototype
name: ~
# The maximum number of redirects to follow.
max_redirects: ~
# The default HTTP version, typically 1.1 or 2.0, leave to null for the best version.
http_version: ~
So http_version goes under default_options
# config/packages/framework.yaml
framework:
http_client:
default_options:
http_version: '2.0'
bin/console debug:config framework http_client
Current configuration for "framework.http_client"
=================================================
default_options:
http_version: '2.0'
headers: { }
resolve: { }
retry_failed:
enabled: false
retry_strategy: null
http_codes: { }
max_retries: 3
delay: 1000
multiplier: 2
max_delay: 0
jitter: 0.1
enabled: true
scoped_clients: { }
Related
I am using Kratos in my local environment just fine, works great and does what I want it to do, however the main issue I am facing is when I moved my ory kratos location to a droplet and my frontend to my vercel. On the droplet I have setup kratos as show here with nginx. After setting it up I tested my login flow and got these error's when I requested /self-service/registration/flows?id=${flowId}
Thinking I setup my config incorrectly I set it up as seen here.
version: v0.10.1
dsn: postgres://kratos:MYPASSWORD/kratos?sslmode=disable&max_conns=20&max_idle_conns=4
serve:
public:
base_url: http://127.0.0.1:4433/
host: 127.0.0.1
cors:
allow_credentials: true
allowed_origins:
- https://frontend.example.com
allowed_methods:
- POST
- GET
- PUT
- PATCH
- DELETE
allowed_headers:
- Authorization
- Cookie
- Content-Type
exposed_headers:
- Content-Type
- Set-Cookie
enabled: true
admin:
base_url: http://kratos:4434/
host: 127.0.0.1
selfservice:
default_browser_return_url: https://frontend.example.com
allowed_return_urls:
- https://frontend.example.com
methods:
password:
enabled: true
oidc:
enabled: false
flows:
error:
ui_url: https://frontend.example.comerror
settings:
ui_url: https://frontend.example.comsettings
privileged_session_max_age: 15m
recovery:
enabled: true
ui_url: https://frontend.example.comrecovery
verification:
enabled: true
ui_url: https://frontend.example.comverification
after:
default_browser_return_url: https://frontend.example.com/
logout:
after:
default_browser_return_url: https://frontend.example.com/
login:
ui_url: https://frontend.example.com/login
lifespan: 10m
registration:
lifespan: 10m
ui_url: https://frontend.example.com/registration
after:
password:
hooks:
- hook: session
oidc:
hooks:
- hook: session
log:
leak_sensitive_values: false
# set in SECRETS_COOKIE and SECRETS_DEFAULT env variables
secrets:
default:
- 795135465767325463454 #fake
cookie:
- 223108c7839f6324242342 #fake
cookies:
domain: frontend.example.com
path: /
same_site: Lax
session:
lifespan: 72h
cookie:
domain: frontend.example.com
path: /
same_site: Lax
hashers:
argon2:
parallelism: 1
memory: 128MB
iterations: 2
salt_length: 16
key_length: 16
identity:
default_schema_id: default
schemas:
- id: default
url: file:///root/kratos/config/identity.schema.json
courier:
smtp:
connection_uri: smtps://test:test#mailslurper:1025/?skip_ssl_verify=true
The issue still persisted so I checked my code
const req: any = await fetch(`https://frontend.example.com/self-service/${flow}/flows?id=${flowId}`, {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
credentials: 'include',
}).catch((err) => {
throw err;
}); //error
everything seems fine, I have credentials and my Content-Type was correct, Then doing some research I found this https://github.com/ory/kratos/issues/662 I was wondering, would this effect me in my situation (I have my frontend domain https://frontend.example.com and my kratos droplet https://kratos.example.com are examples), and if so how I could go about fixing it(could I use the ory-proxy to get cookies to my application safely?)? My idea was that I could simply setup ory hydra has the oauth provider for my platform but I am not sure.
Also,
Thanks in advance!
I try to configure nelmio/api-doc-bundle to use Authorization header for my Bearer token.
I configure it in nelmio_api_doc.yaml like this
nelmio_api_doc:
documentation:
info:
title: title
version: 1.0.0
securityDefinitions:
Bearer:
type: apiKey
description: 'jwt from oauth prefixed by `Bearer`'
name: Authorization
in: header
security:
- Bearer: []
areas: # to filter documented areas
path_patterns:
- ^/api(?!/doc$|/doc.json$) # Accepts routes under /api except /api/doc and /api/doc.json
But when i got to the ui doc page I got :
Notice: Undefined index: securityDefinitions
Did someone know how to fix it ?
It was changed in version 4, check this docs https://symfony.com/doc/4.x/bundles/NelmioApiDocBundle/index.html#using-the-bundle
I try the Restfulapi addon for silverstripe 4 and my configuration is:
integre\About:
api_access: true
integre\Home:
api_access: true
Image:
api_access: true
File:
api_access: true
integre\Theatre:
api_access: true
# RestfulAPI config
Colymba\RESTfulAPI\RESTfulAPI:
authentication_policy: false
access_control_policy: 'ACL_CHECK_CONFIG_AND_MODEL'
cors:
Enabled: true
Allow-Origin: '*'
Allow-Headers: '*'
Allow-Methods: 'OPTIONS, POST, GET, PUT, DELETE'
Max-Age: 86400
but when i try http://localhost/integre/api/Theatre/1 i receive
{
"code": 400,
"message": "Model does not exist. Received 'Theatre'."
}
how to fix this?
Your problem is that you're using a namespaced class and not correctly configuring it to be used in the API, so it's not resolving correctly. Looking at DefaultQueryHandler, you need to define a class name map for this:
Colymba\RESTfulAPI\QueryHandlers\DefaultQueryHandler:
models:
Theatre: integre\Theatre
This tells the query handler to load integre\Theatre when it is asked for a Theatre model. Note that your Image and File references in your configuration are also missing their namespaces.
I work on Symfony 2.3 and I installed MobileDetectBundle that works on this symfony version:
(in my composer.json)"suncat/mobile-detect-bundle": "0.10.3"
(in packagist)https://packagist.org/packages/suncat/mobile-detect-bundle#v0.10.3
I configured the bundle accordingly
AppKernel.php
new SunCat\MobileDetectBundle\MobileDetectBundle(),
config_mobile.yml
mobile_detect:
redirect:
full:
is_enabled: true # default false
host: http://page.com # with scheme (http|https), default null, url validate
status_code: 301 # default 302
action: redirect # redirect, no_redirect, redirect_without_path
mobile:
is_enabled: true
host: http://m.page.com
status_code: 301
action: redirect
tablet:
is_enabled: true
host: http://t.page.com
status_code: 301
action: redirect
switch_device_view:
save_referer_path: true
service:
mobile_detector: mobile_detect.mobile_detector.default
device_view_class: SunCat\MobileDetectBundle\Helper\DeviceView
request_listener_class: SunCat\MobileDetectBundle\EventListener\RequestListener
extension_class: SunCat\MobileDetectBundle\Twig\Extension\MobileDetectExtension
in my service.yml
services:
mobile_detector: #mobile_detect.mobile_detector.default
in app_mobile.php
$kernel = new AppKernel('mobile', false);
The bundle works with the mobiledetect classes. Both of them are present in my vendor, so I guess that the installation was done properly
I restarted my server, PHP, cleared the cache but still it doesn't show me my redirection in the URL.
Is it possible in some cases that Symfony doesn't recognize a bundle? Does that happens depending on the version you are?
Try this :
mobile_detect:
redirect:
mobile: ~
tablet: ~
switch_device_view: ~
I am using FosElasticaBundle in a Symfony project. I configured my mappings but I get exception "expected a simple value for field [_id] but found [START_OBJECT]]".
I'd like to see the actual JSON created by FosElasticaBundle so I can directly test it against my ElasticSearch server, and understand more about the exception.
According to FosElastica documentation, everything should be logged when debug mode is enabled (i.e. in DEV environment) but I can't see this happening; I only see Doctrine queries, but no JSON.
How can I dump the JSON created by FosElasticaBundle?
Update: mappings
# FOSElasticaBundle
fos_elastica:
clients:
default: { host: %elasticsearch_host%, port: %elasticsearch_port%, logger: false }
indexes:
app:
types:
user:
mappings:
name: ~
surname: ~
persistence:
driver: orm
model: AppBundle\Entity\User
provider: ~
listener: ~
finder: ~
I think you should only set your logger to true instead of false
fos_elastica:
clients:
default:
host: %elasticsearch_host%
port: %elasticsearch_port%
logger: true <---- set true here
...