An extension to remember authenticated visitors on your Bolt website. This extension uses HybridAuth for the actual authentication process
To enable a provider set the value enabled: true
in the configuration and
replace the example provider keys with real values. (see below)
- Login to https://console.developers.google.com/project
- Click 'Create Project' (go to next step if using an existing one)
- Set a descriptive Project Name
- Agree to terms and services
- Click Create
- Expand 'APIs & auth' menu and select 'Credentials'
- Under 'OAuth' click 'Create new Client ID'
- Click 'Configure consent screen'
- Set your desired email address from the selector
- Set a unique 'Product Name'
- Click 'Save'
- In the 'Create Client ID' dialogue
- Set Application Type: Web Application
- Set Authorized JavaScript Origins: http://your-bolt-site.example.com
(change the domain name to match yours) - Set Authorized Redirect URI: http://your-bolt-site.example.com/oauth2/callback?provider=Google
(change the domain name to match yours) - Click 'Create Client ID'
- Under the 'APIs & auth' menu select 'APIs'
- Click the 'Google+ API' link (middle of the page at time of writing)
- Click the 'Enable API' button
- Click the 'Explore this API' link
- Click the 'Authorize requests using OAuth 2.0' switch (top right)
- On the 'Authorize requests using OAuth 2.0' dialog enable: * Authorize requests using OAuth 2.0 (Authorize requests using OAuth 2.0) * Know who you are on Google (https://www.googleapis.com/auth/plus.me) * View your email address (https://www.googleapis.com/auth/userinfo.email) * View your basic profile info (https://www.googleapis.com/auth/userinfo.profile)
- Add the 'Client ID' and 'Client Secret' to your config.yml
NOTE It may take as long as 10 minutes for the changes to propagate and the client ID and secret to work
- Login to Facebook with the account you want to use for the site
- Go to https://developers.facebook.com
- Under the 'Apps' menu select 'Create a New App'
- In the 'Create a new app' dialogue set:
- 'Display Name' set to something descriptive
- 'Namespace' just leave blank
- 'Is this a test version of another app?' leave as 'No'
- 'Category' just select a category that fits your site content
- Click 'Create App' and enter displayed CAPTCHA
- At this point your app is created in development mode and you will be redirected to the App Dashboard.
- In the left menu, select 'Settings'
- In the 'App Domains' field enter your sites domain name:
- your-bolt-site.example.com
(change the domain name to match yours) - In the 'Contact Email' field enter your sites contact email address:
- someone@your-bolt-site.example.com
(change the address to match your site's) - Click 'Add Platform' button
- Choose "Website" in displayed dialogue
- Enter your site's relevant URLs:
- 'Site URL' - http://your-bolt-site.example.com
- 'Mobile Site URL' - http://mobile.your-bolt-site.example.com
(change the domain name to match yours) - Click 'Save Changes'
- In the left menu, select 'Status & Review'
- Set the toggle next to "Do you want to make this app and all its live features available to the general public?" to Yes
- Click 'Confim' in the displayed dialogue
- In the left menu, select 'Dashboard'
- Add the 'App ID' and 'App Secret' to your config.yml file
Multiple URLs
- Go to https://developers.facebook.com
- In the left menu, select 'Settings'
- Select the 'Advanced' tab
- Scroll down to the 'Security' section of the page
- Add URLs to the 'Valid OAuth redirect URIs' field
- Log into GitHub
- Go to: https://github.com/settings/applications/
- Click 'Register new application'
- Fill in the fields:
- Application name
- Homepage URL: http://your-bolt-site.example.com (change the domain name to match yours)
- Application description
- Authorization callback URL: http://your-bolt-site.example.com/oauth2/callback?provider=Github
(change the domain name to match yours) - Click 'Register application'
- Add the 'Client ID' and 'Client Secret' to your config.yml
To use the password authentication you also need to install BoltForms.
See the hybrid auth userguide for advanced configuration options.
You can use the following functions and snippets in your templates
There are two Twig function options for displaying the login links:
{{ displaylogin() }}
{{ displaylogin(true) }}
In the first instance, after authentication a user is redirected to the homepage.
By supplying the parameter true
the user is redirected to the current page.
As with login, there are two options for the logout links:
{{ displaylogout() }}
{{ displaylogout(true) }}
In the first instance, after logging out a user is redirected to the homepage.
By supplying the parameter true
the user is redirected back to the current page.
If you want the login/logout to be automatically varied based on whether a user is logged in or our, you can use:
{{ displayauth() }}
Twig templates used by ClientLogin can be overridden in your config file.
Assuming you're using a theme directory of theme/my-site-theme/
you can:
- Create the directory
theme/my-site-theme/extensions/clientlogin/
- Copy the contents of
extensions/vendor/bolt/clientlogin/assets/
totheme/my-site-theme/extensions/clientlogin/
- In your
app/config/extensions/clientlogin.bolt.yml
file, set thetemplate
key to something similar too:
template:
login: extensions/clientlogin/_login.twig
password: extensions/clientlogin/_password.twig
password_parent: extensions/clientlogin/password.twig
feedback: extensions/clientlogin/_feedback.twig
button: extensions/clientlogin/_button.twig
At this point you can customise the files in theme/my-site-theme/extensions/clientlogin/
as you need for your site.
This extension is pretty bare-bones by design. Most likely, you will use this extension in combination with another extension that builds on its functionality.
To get information about the current visitor:
if ($this->app['clientlogin.session']->doCheckLogin()) {
// User is logged in
if ($this->app['clientlogin.db']->getUserProfileBySession($this->app['clientlogin.session']->token)) {
$username = $this->app['clientlogin.db']->user['username'];
$provider = $this->app['clientlogin.db']->user['provider'];
$providerdata = json_decode($this->app['clientlogin.db']->user['providerdata']);
}
}
If you want to hook into login/logout events, ClientLogin dispatches events to
listeners on clientlogin.Login
and clientlogin.Logout
.
You can add the hooks and specify callback functions like so:
$this->app['dispatcher']->addListener('clientlogin.Login', array($this, 'myLoginCallback'));
$this->app['dispatcher']->addListener('clientlogin.Logout', array($this, 'myLogoutCallback'));
Inside your callback you can get the array of user profile data for the login/logout with:
public function myLoginCallback(\Bolt\Extension\Bolt\ClientLogin\ClientLogin\Event\ClientLoginEvent $event)
{
$userdata = $event->getUser();
}