I wonder if there is a difference between:
the router I can reach from a command script, using $this->getContainer()->get('router') and
the one I can reach from a controller, using $this->get('router').
I have set the base url parameter "router.request_context.base_url" in app/config/parameters.yml
This base url appears in urls generated by the "command" router, but not in urls generated by the "controller" router.
Did I miss something?
router.request_context.base_url is only used by the "command" router. The router used in your controllers will use the current URL as the base URL. You have a flag to set when calling the generate() function in order to have the absolute URL:
$this->get('router')->generate('myroute'),
$this->get('router')->generate('myroute', array(), true)
Will output:
/myroute
http://development.www.myapp.com/myroute
Related
I have a RedwoodJS App with several routes.
It's very basic for now and I start the development server with yarn rw dev.
Now I have created some routes:
/ -> HomePage
/sign-in -> SignInPage
/register -> RegisterPage
I can call the routes internally via navigate which works fine. But I cannot call these routes via localhost:8910/register for example. I get a 404 error.
What do I have to do to make (almost) all routes callable directly with their absolute urls?
A late response to your question, but all the routes are managed in the Routes.tsx-file. In my example, I have a route to access the BikesPage-component (located in .../pages/Bike/BikesPage hence the naming BikeBikesPage).
So to ask your question, to make them callable by their absolute name, the name must be the same as the path. Hope that helped you or anyone coming here afterwards!
I have two firewalls in my Symfony (5.4) application.
What I want is to create a login link for another firewall (where the login_link is configured) while logged in into the other firewall.
Currently the system doesn’t allow that (No Symfony\Bundle\SecurityBundle\LoginLink\LoginLinkHandler found for this firewall. Did you forget to add a "login_link" key under your "admin_area" firewall?)
Is there a way to tell the login link creator to create the link for a specific firewall? (I didn’t see it in the implementation so I don’t really know).
UPDATE 2022-06-10: Beginning with Symfony 6.1, just use the new Autowire-Attribute like this:
public function myLoginLinkAction(
User $myUser,
#[Autowire(service: 'security.authenticator.login_link_handler.my_other_firewall')] LoginLinkHandlerInterface $myOtherFirewallLoginLinkHandler,
): Response
{
// …
$loginLinkDetails = $myOtherFirewallLoginLinkHandler->createLoginLink($myUser);
// …
}
For older Symfony versions:
The solution is to inject the concrete link handler service for my other firewall using an alias defined in security.yaml (where the other firewall that we want to build login links for is named "my_other_firewall"):
services:
# define a concrete alias for the login link handler of the
# my_other_firewall firewall to avoid the FirewallAwareLoginLinkHandler
# that always uses the current request's firewall
Symfony\Component\Security\Http\LoginLink\LoginLinkHandlerInterface $myOtherFirewallLoginLinkHandler: '#security.authenticator.login_link_handler.my_other_firewall'
Then, when I inject the LoginLinkHandlerInterface to my login link building controller, I use the defined parameter name $myOtherFirewallLoginLinkHandler and get the correct LoginLinkHandler injected instead of the FirewallAwareLoginLinkHandler that only exists to use the LoginLinkHandler defined for the firewall of the current request.
This solves the problem the documented way to use concrete implementations, when more than one implements a certain interface.
I have a route called "/song", which takes parameters. And this is how I access within the app:
() => Navigator.pushNamed(context, "/song", arguments: "my_id");
How can I convert URL params to in-app route arguments?
Example:
When I open https://myapp.page.link/song&id=some_id, it opens /song route with "some_id" argument.
NOTE: Data is dynamically loaded on both website and app, therefore it's very impractical to implement deep link for each one of them manually.
I want to configure my proxy in the following fashion.
All requests by default get passed through to http://main.api.com
Any request that has has a URI path that start /admin gets routed to http://admin.api.com
<RouteRule name="mocker">
<Condition>(proxy.pathsuffix JavaRegex "^/admin/?.*$")</Condition>
<TargetEndpoint>MockTarget</TargetEndpoint>
</RouteRule>
<RouteRule name="default">
<TargetEndpoint>default</TargetEndpoint>
</RouteRule>
This partially works in that it does indeed route to a different host. However, it maintains the path; so requesting /admin/foo/bar gets redirected to http://admin.api.com/admin/foo/bar, but I wanted it to go to http://admin.api.com/foo/bar
How can I achieve that?
You will have to set target.copy.pathsuffix to false in the Target PreFlow. This will ensure that the path from Proxy is not copied to the Target.
You can easily do this by adding a Javascript policy on the Target Preflow with the code
context.setVariable("target.copy.pathsuffix", false);
I am applying this tutorial into symfony 2.4, I've finished the setup in the config.yml and everything, I managed to visit the admin/google/analytics page, but the problem is when I tried to authenticate with the parameters I've created in the config.yml file, it is searching for the scope, here is the parameters.
happy_r_google_analytics:
host: www.example.com
profile_id: MyProfileId
tracker_id: UA-TRACKER-ID
token_file_path: %kernel.root_dir%/var/storage
happy_r_google_api:
application_name: Project Default Service Account
oauth2_client_id: OAuthClientID
oauth2_client_secret: OAuthClientSecret
oauth2_redirect_uri: http://www.example.com/app_local.php/admin/google/analytics/oauth2callback
developer_key: DevelopperKey
site_name: http://www.example.com
I think there's no problem here, I've got no idea where I can set the scope so the google Api client can set it to https://www.googleapis.com/auth/analytics.readonly
You need to define a scope. If you use Google Auth, check Authorization scopes for it.
You must do something like:
$googleClient = new \Google_Client();
$googleClient->setScopes(array(
'https://www.googleapis.com/auth/plus.me',
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile',
));