Where do I find the route name for logging in with facebook? I don't want to hardcode the routes into the twig templates.
Short answer
Route name is hwi_oauth_service_redirect:
Name Method Scheme Host Path
hwi_oauth_service_redirect ANY ANY ANY /connect/{service}
So, for facebook you can generate connect route in view via:
{{ path('hwi_oauth_service_redirect', { service: 'facebook' }) }}
How to debug similar problems
I was also amazed how HWIOAuthBundle doesn't mention route name in documentation anywhere, or at least it isn't obviously stated and I couldn't find it.
When you have this kind of problem, you can use $ app/console router:debug command, which will provide you dump of all routes defined.
Related
I tried to configure Elasticsearch for monolog as mentioned here but the problem is that I don't find any way to pass my username and password for Elasticsearch since the ElasticsearchLogstashHandler service only takes an endpoint as input.
here's the service that I created:
elasticsearch_logstash_handler:
class: Symfony\Bridge\Monolog\Handler\ElasticsearchLogstashHandler
arguments: [ '%ELASTIC_SEARCH_ENDPOINT%']
I tried to put username and password in the URL (username:password#url) but since the password contains special characters it doesn't work this way.
thank you for sharing your ideas.
I want to write a script that send notification mails to users and execute it every hour and I want it to match the server name that host the symfony site. I've already tried with $_SERVER but it's not defined and the solution on this post but there is no request with the console so it's does work.
Since there is no traditional 'web request/response' thing in console command, all URLs you generate with {{ path('...') }} in twig or $this->generateUrl('...') or similar controllers/services´, will be probablyhttp://localhost/...
To fix that, simply add: (if you're on symfony 5.1+)
# config/packages/routing.yaml
framework:
router:
# but you should move it to your .env file and user two differen env-variables for host and scheme
default_uri: 'https://you-site-hostname.com/'
or if you are using older version, put
router.request_context.scheme and router.request_context.host to you parameters. Like
# config/services.yaml
parameters:
router.request_context.scheme: 'https'
asset.request_context.host: 'you-site-hostname.com'
Take a look here: https://symfony.com/doc/current/routing.html#generating-urls-in-commands
And here (my personal advice) https://symfonycasts.com/screencast/mailer/route-context
I am trying to configure HWIOAuth bundle to use dynamic client id. I have a service that can figure out what variable value to use depending on some request conditions.
Here's an expression in my HWI configuration, but can't seem to get it work:
hwi_oauth:
firewall_names:
- main
resource_owners:
auth:
client_id: "#=service('host.configmgr').GetClientIdParameter()"
client_secret: '%client_secret%'
The issue us with #=service('host.configmgr').GetClientIdParameter(). Can that even execute evaluate? The service is properly executes an used by another class somewhere else with success.
The %client_secret% parameter replacement works fine.
For more context, this part of the configuration lives in a dedicated file that is included in config.yml via { resource: hwiconfig.yml }
After some research looks like expressions are only supported for service definitions. This functionality is not supported for configurations outside services like the HWI bundle config.
I found an easy way of adding a locale to my Symfony routes, as described here: Locale switch in login of FOSUserBundle
Some relevant settings in my project:
config
framework:
translator: { fallback: "%locale%" }
default_locale: nl
services
fosmailer: #fos_user.mailer.twig_swift
routing
fos_user_register:
resource: "#FOSUserBundle/Resources/config/routing/registration.xml"
prefix: /{_locale}/registreren
I'm trying to get FOSUser to send a confirmation mail in the newly created users' browserlanguage.
For this I'm saving the locate found by javascript in my database.
Then, I'm setting my request to that locale and send the confirmation mail manually like this:
$request->setLocale($locale); //($locale = 'en_US')
$mailer = $this->get('fosmailer');
$mailer->sendConfirmationEmailMessage($user);
My email template contains a bunch of {{ 'foobar' | trans}} tags, which work perfectly fine. But I'm also using the {{confirmationUrl}} which is generated by FOSUser.
In an English mail this confirmation url will still show up as:
/nl/registreren/confirm/1234..
Any ideas why my mail is localized but my url isn't?
The URL address is not translated, because localization of URL addresses is not part of standard Symfony2 installation.
In order to localize URL addresses you need to use some bundle which solves this issue, for example BeSimpleI18nRoutingBundle or you can create your own solution.
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',
));