admad / cakephp-hybridauth Goto Github PK
View Code? Open in Web Editor NEWCakePHP plugin for HybridAuth
License: MIT License
CakePHP plugin for HybridAuth
License: MIT License
Cant post to page. I got all needed params but when I try to execute $pages->api()->api( "/" . $pages['data'][0]['id'] . "/feed", 'post', $params ); i get
Call to a member function api() on array
Hello,
bin/cake migrations migrate -p ADmad/HybridAuth
does not create the table. I only see the phinx table with a strange name
a_dmad_hybrid_auth_phinxlog
Hey dude, me again :P
I developed all my website using Windows, but when I put it on my server (runs Linux) it got some fatal erros. Just little things like this
Just creating the issue to let you know this
Hybrid auth is not writing associated models of User while doing $this->Auth->login().
The authenticated action on the HybridAuthController
will sometimes render a white page.
To reproduce visit the URL by manually entering the address.
http://www.example.com/hybrid_auth/authenticated
Sometimes when the OAuth process fails the user is left on this address with a white page. It should redirect to some of the auth redirect URLs.
Now that CakePHP 3.0 is released. Can the Cake3 branch become the master, and the master be branched for Cake2.
I'm not sure how this would impact composer, but Cake2 doesn't use composer. So people would just have to remove the branch reference.
The plugin should maybe use a release tag as well.
In documentation the example about openID, how to integrate HybridAuth with facebook, twitter, etc ?
Since you have again started working on this, do you plan to have a CakePHP 3 branch?
HybridAuthAuthenticate
current fetches the user record as an CakePHP entity. This causes the AuthComponent
to return the user record as an entity for the first time, but later when the user is fetched from the session it's an array.
This breaks code because $this->Auth->user()->id
is valid only when it's not from the session.
Hello,
we should add another check here: https://github.com/ADmad/CakePHP-HybridAuth/blob/event/src/Auth/HybridAuthAuthenticate.php#L206-L213
if the result is an entity we should return $result->toArray();
without doing the query again. What do you think?
After authentication (after first registration), I'm getting this message :
Notice (8): Undefined variable: UsersTable [ROOT/vendor/admad/cakephp-hybridauth/src/Auth/HybridAuthAuthenticate.php, line 289]
Fatal Error
Cake\Error\FatalErrorException
Error: Call to a member function primaryKey() on null File /home/user10/public_html/app/vendor/admad/cakephp-hybridauth/src/Auth/HybridAuthAuthenticate.php Line: 289
How to fix this ?
The documentation of this plugin says to check the examples of the Hybrid Auth docs but there is a red box on the page telling me this:
Please note that the examples are outdated and not production ready.
New examples are planned in one of the future releases.
So how do I set this up to work with a few different remote logins? FB, Twitter and Facebook to be specific.
I am using ADmad/CakePHP-HybridAuth with dereuromark/cakephp-tinyauth with multi role facility. I wrote following code in my AppController.php
:
$this->loadComponent('TinyAuth.Auth', [
'autoClearCache' => true,
// followings are common setting for auth component
'authenticate' => [
'Form' => [
'finder' => 'auth'
],
'ADmad/HybridAuth.HybridAuth' => [
'fields' => [
'provider' => 'provider',
'openid_identifier' => 'openid_identifier',
'email' => 'email'
],
'profileModel' => 'ADmad/HybridAuth.SocialProfiles',
'profileModelFkField' => 'user_id',
'hauth_return_to' => ['controller' => 'Users', 'action' => 'index', 'prefix' => false, '_ext' => null],
]
],
'loginAction' => [
'controller' => 'Users',
'action' => 'login',
'prefix' => false
],
'loginRedirect' => [
'controller' => 'Users',
'action' => 'index',
'prefix' => false
],
'logoutRedirect' => [
'controller' => 'Users',
'action' => 'login',
'prefix' => false
],
'flash' => [
'element' => 'error',
'key' => 'auth'
],
// using bootstrap ui for flash element
'flash' => [
'element' => 'error',
'key' => 'auth'
],
'authorize' => [
// check authorization using TinyAuth based on config/acl.ini settings
'TinyAuth.Tiny' => [
'multiRole' => true,
'autoClearCache' => true,
'superAdminRole' => '01',
'rolesTable' => 'roles',
'pivotTable' => 'roles_users'
]
]
]);
When I try to login using form
it returns associated roles
, but when try to login using HybridAuth
not returned the roles
. FYI, authentication and authorization works for both case.
I am using CakePHP 3.3.5. I also try using contain
, which have been deprecated as of 3.1, but no roles
return for HybridAuth
. I also try my custom finder findAuth
for HybridAuth
, no change.
FYI, when I save new user using \Cake\Event\EventManager::instance()->on('HybridAuth.newUser', [$this, 'createUser']);
, my associated roles
saved successfully.
How can I retrieve roles
using HybridAuth
?
I have the following problem.
What I want is that of a user press a link to /baskets/save to redirect him to login and then later on to /baskets/save again.
In /baskets/save:
if(!$this->Auth->user()) {
$this->request->session()->write('goto', ['controller' => 'Baskets', 'action' => 'save']);
return $this->redirect('/users/login');
}
and in users/login:
if($goto && count($goto) > 1)
$this->Auth->redirectUrl(array_merge($goto, ['plugin' => false]));
but then I get an error:
Error: A route matching "array ( 'controller' => 'Users', 'action' => 'login', 'plugin' => 'ADmad/HybridAuth', '_ext' => NULL, )" could not be found.
The error occurs in HybridAuthController.php on line 50:
if ($user) {
$this->Auth->setUser($user);
return $this->redirect($this->Auth->redirectUrl()); <------------- here
}
What am I doing wrong?
Hi,
I've tried your plugin and i've setup my facebook application but I have to press the button twice in order to login.
I've narrowed it down to if ($this->request->is('post')) {
in the controller login function. This returns false when you first submit this form.
<?php
echo $this->Form->create('User');
echo $this->Form->input('provider', array('value' => 'Facebook'));
echo $this->Form->end('Submit');
?>
Apparently the first time you click to login with facebook, the plugin via the library communicates well with facebook servers but then it won't go straight into $this->Auth->login()
(to actually log you in the first time) because when it comes back from facebook through the endpoint it's not a post anymore and that's why when you press the button to login with facebook a second time, it will work because it already has the facebook stuff stored in session and then its actually a post.
I haven't tried other services yet.
Thanks.
Later EDIT
Twitter behaves the same way, having to submit the form twice because it stops at the same if condition, the request that comes back from twitter is not post so it doesn't go into $this->Auth->login()
Hi,
is it possible to use hybridauth with multiple providers per user? Like an 1:n relationship between users table and providers table?
Hello @ADmad,
I'm trying to use your plugin from composer, but app doesn't start due to this error:
Fatal Error
Error: Class 'Hybrid_Auth' not found
File:
C:\wamp\www\app\Plugin\HybridAuth\Controller\Component\Auth\HybridAuthAuthenticate.php
Line: 141
Note: After adding hybridauth into require-dev of composer.json and execution composer update, it has been installed in C:\wamp\www\app\Vendor.
composer.json details:
"require": {
"pear-cakephp/cakephp": ">=2.4.4"
, "cakephp/debug_kit": ">=2.2.2"
, "admad/cakephp-hybridauth": "dev-master"
},
"require-dev": {
"phpunit/phpunit": "3.7.*"
, "hybridauth/hybridauth": "dev-master"
}
Do you know what is wrong?
Hello,
after login i get few information of the user, this is the output of $this->Auth->identify()
[
'identifier' => '102062xxxxxx',
'webSiteURL' => '',
'profileURL' => '',
'photoURL' => 'https://graph.facebook.com/102062xxxxxx/picture?width=150&height=150',
'displayName' => 'Name Surname',
'description' => '',
'firstName' => '',
'lastName' => '',
'gender' => '',
'language' => '',
'age' => null,
'birthDay' => null,
'birthMonth' => null,
'birthYear' => null,
'email' => '',
'emailVerified' => '',
'phone' => null,
'address' => null,
'country' => null,
'region' => '',
'city' => null,
'zip' => null,
'username' => '',
'coverInfoURL' => 'https://graph.facebook.com/102062xxxxxx?fields=cover&access_token=xxxxxxx'
]
It is strange because i am using this scope email, public_profile, user_friends
.
When i see the dialog on the facebook's page i correctly see that app is asking for email, public profile and friends, but the result does not have those information. Why?
In server error logs: I can see following message
Argument 1 passed to App\Model\Table\UsersTable::createUser() must be an instance of App\Model\Table\Event, instance of Cake\Event\Event given
And socialprofile & users both table dont have entry for these users
can you change table name from social_profiles to something else?
i tried changing this 'profileModel' => 'ADmad/HybridAuth.SocialProfiles', and this $this->hasMany('ADmad/HybridAuth.SocialProfiles');
but still ain working.
please help
Hello Admad,
First off, this plugin has been so useful, thank you for making it.
Having an issue since upgrading to the newest version of CakePHP. Now when clicking on login from Google or Facebook, I'm logged in but never get redirect to the provider site and no provider_uid is generated.
Keeps generating users in the database on every click, I've not changed any code and only noticed since upgrading.
Any ideas? I'll set up a blank project and see If I can replicate what is happening.
Thank you.
What I'm doing
?provider=Twitter
etc, as detailed in the docsexample.com
to my localhost
so that OAuth callback urls resolve correctly.exit
inside my createUser()
method to see the web service return and my newly built UserEntity
.What is happening
After trying Twitter for example, I then refresh my login page and click to sign in with Google, and I get a Twitter response.
What I'm expecting
My expectation would be that the return of $event->data()['profile']
would match the provider passed in the query param.
What could be happening?
I've not done too much investigation at this point, but I can only imagine that there is some caching of the web service response somewhere. It's worth noting that this behaviour doesn't happen all the time, and seems to be triggered by sending many request, so could be a side effect of development.
I wanted to raise an issue for a number of reasons. Firstly so that I know I won't forget it. Secondly so if anyone else hits the issue we can collate thoughts, and thirdly to get some input on potential failure points and things to debug.
Hi =)
<?= $this->Html->link(
'Login with Facebook',
['controller' => 'Users', 'action' => 'login', '?' => ['provider' => 'Facebook']]
); ?>
After being authentified by facebook when i go back to the login page and click again on the facebook connexion, i'm getting
Error: A route matching "array ( 'controller' => 'users', 'action' => 'login', 'prefix' => false, 'plugin' => 'ADmad/HybridAuth', '_ext' => NULL, )" could not be found.
Do i have to setup a route in routes.php ?
The passed context was:
[
'_base' => '',
'_port' => '80',
'_scheme' => 'http',
'_host' => 'www.myprivatedomain.com',
'params' => [
'plugin' => 'ADmad/HybridAuth',
'controller' => 'HybridAuth',
'action' => 'authenticated',
'_ext' => null,
'pass' => [],
'_matchedRoute' => '/hybrid-auth/authenticated'
]
]
Hi!
Why should we use the email field inside social_profiles table?
In the users table we already have email field. When we use two or more socials we use that field to understand if the user is already registered. social_profiles.email
is only a "clone" of that field, looks useless to me. What do you think?
Hi Admad,
Authentication not respond. Then I change HybridAuthAuthenticate.php on Line : 239
from : $provider = $data[$fields['provider']];
with : $provider=$data['provider'];
I am not sure but it work now.
Great & Simple Plugin
Thank bro.
Hi there.
First of all, thanks for this plugin, really great ;)
I'm trying to do something.
So on my Users/login, the users choose which social they want to login.. Lets imagine facebook. They click on it, authorize it and then I want it to redirect to a page where he writes extra information ( I know this is not usual, but it's how the platform is built, and we need some extra information from the user, such as VAT number and such)
I already got the redirect working properly ('hauth_return_to' => 'users/add'). Though, I don't know how in users/add.ctp get the user from social and fullfill my form with some information from
Thanks a lot!
Right now I am working on project where we need facebook and twitter login.
And I have also configure the login in my project but now its not authenticate with simple username and password.
This is AppController.php
class AppController extends Controller
{
public function initialize()
{
$this->loadComponent('Flash');
$this->loadComponent('Auth', [
'loginRedirect' => [
'controller' => 'Users',
'action' => 'index'
],
'logoutRedirect' => [
'controller' => 'Users',
'action' => 'login'
],
'authenticate' => [
'ADmad/HybridAuth.HybridAuth'
]
]);
}
}
Its working with only facebook and twitter login,and please let me know how to store user in database after successful login in fb or twitter.
When I run bin/cake migrations migrate -p ADmad/HybridAuth
to generate table it gives
Plugin Admad/HybridAuth could not be found. in [/var/www/html/site/vendor/cakephp/cakephp/src/Core/Plugin.php, line 148]
I am trying to use your plugin with php 5.5.9 (ubuntu 14.04) and the following line
App::import('Hybridauth.Vendor', 'hybridauth/Hybrid/Auth') fails to import the file. Leading to a Class not found error. Instead i had to use require_once()
FWIW the current code runs just fine in php 5.5.3
You may or may not want to fix this...
Just a small heads up and reminder ticket once 3.4 becomes beta/stable
We should add support for query string redirects then, so the referrer after login still is applied as so far with session approach.
Hi,
looks a bit strange to me adding a new user inside the authenticate file. If i can ask, why this choice? I think we should trigger the newUser
event and then all the logic must be in the controller.
A new type of authentication should check if it is able to authenticate the user, nothing else.
Do we need a refactorization?
first of all i would like to say sorry for posting such a stupid question, i have download this plugin and loaded to my application and configure my controller and config file as defined, but i cannot see any info that tells my how should i configure my login.ctp file, i tried to implement the src/template/login.ctp code found in the repo but that doesnt work in my app. i cannot see any link that says login with facebook and others. can you please point out to correct doc if any i am using cake 3
Hello,
looking at the login page we simple do $user = $this->Auth->identify();
The problem here should be if we manage more providers. Because the identify() method calls the provider login page but what if we have many, what happen ?
How should we set the specific provider we need to identify?
Right now the plugin stores all of the user record fields in the session. Would be nice if the config could define what fields should be stored.
Hi,
I have a plugin in which I have a Users controller and Model. I followed all the steps you mentioned and added the listener in UsersTable.php of my plugin but when the callback from Google arrives the execption in line 339 of HybridAuthAuthenticate.php is triggered and I see the error : "You must attach a listener for "HybridAuth.newUser" event which saves new user record and returns an user entity."
Could you help me please?
After a successfull login, the info about the user should be on $this->Auth->user() or not ?
I guess not because mine isn't.
I did some research on the plugin and library code, and found the info on $_SESSION["HA::STORE"]['hauth_session.provider.user']. You plan put it on Auth->user() ? I tried to do this, but i don't understand very well about Components.
Sry for bad english
It would be nice to have extension points for HybridAuthController::authenticated().
This way we can execute the same after login logic like the normal login would, or via protected AppController method use the same one for both.
Ideally there is one for the success (e.g. logincounter raise) and one for the error case (e.g. flash message).
This is for the 4.0 branch. When I attempt to create the social_profiles table, the following occurs:
Welcome to CakePHP v3.1.2 Console
---------------------------------------------------------------
App : src
Path: /var/www/blah/src/
PHP : 5.6.4-4ubuntu6.3
---------------------------------------------------------------
using migration path /var/www/blah/vendor/admad/cakephp-hybridauth/config/Migrations
using environment default
using adapter mysql
using database nom_dev
== 20150813000000 CreateSocialProfiles: migrating
[PDOException]
SQLSTATE[HY000]: General error: 1005 Can't create table `blah`.`social_profiles` (errno: 150 "Foreign key constraint is incorrectly formed")
migrate [-t|--target TARGET] [-d|--date DATE] [-p|--plugin PLUGIN] [-c|--connection CONNECTION] [-s|--source SOURCE]
Dear ADmad,
Im beginner for cakePHP, I just installed your plugin and confused about how put my provider btn in login page.
if you can explain me more.
thanks
Hi,
I am going to use the version for CakePhp 2.4+ but I am not sure that Instagram login is working properly? As I found some LinkedIn typos in Instagram provider, I've been in doubt if it's working.
Thanks in advance.
Hi,
I updated the Cake version to 3.1 and kept the plugin at the 4.0 branch (worked for me), however after this, the routes to login did not work anymore. For exemple:
/users/login?provider=Google
Gives this error:
Error: A route matching "array ( 'controller' => 'Users', 'action' => 'login', 'plugin' => NULL, '_ext' => NULL, )" could not be found.
If I use any other word (or even left it blank) instead of ?provider=
the routes work ok. Thus this made me believe there was something that changed, am I right or did I do something wrong?
Thanks!
I found a problem attaching the method to handle new registrations.
At the moment i have:
public function beforeFilter(Event $event)
{
parent::beforeFilter($event);
EventManager::instance()->on('HybridAuth.newUser', [$this, 'socialRegistration']);
}
the problem is that the UsersController is never called, HybridAuthController instead because the provider is calling the authenticated method there.
If i put the same beforeFilter inside the AppController it works perfectly, but adding the callback for registration there does not sounds good.
is there any workaround?
I get the following error messages when HybridAuth fails to connect to twitter.
Notice (8): Undefined index: oauth_token
Can you make it throw an exception instead of this?
I'm trying to set this up as a social login for an AngularJS project. Cake is acting as my REST API, and I'm not storing any session data elsewhere. I simply plan on passing in a token on each request for authentication. All I need is for this to manage the OAuth callback and then issue a token back to the AJAX request. Do I need Sessions enabled for that?
Hello @ADmad,
First of all, congratulations for sharing your project. For me, this one is better than suggested by HybridAuth for CakePHP projects
Do you think about include composer.json and share it packagist.org? Currently, I'm using it to download CakePHP, or even DebugKit, and it's a good and usefull way to control third parties in projects and their upgrades.
Thanks.
I keep getting this error:
You must attach a listener for "HybridAuth.newUser" event which saves new user record and returns an user entity.
I use CakePhp 3.2
this is my url
http://www.elearnmarkets.in/elm/login
I've run into the following fatal error attempting to login after installing HybridAuth:
Notice (8): Undefined property: HybridAuthAuthenticate::$_registry [ROOT/Plugin/HybridAuth/Controller/Component/Auth/HybridAuthAuthenticate.php, line 104]
Notice (8): Trying to get property of non-object [ROOT/Plugin/HybridAuth/Controller/Component/Auth/HybridAuthAuthenticate.php, line 104]
I rolled my version of Cake back to the 2.4 branch to check if this might be a result of any core changes that have happened since, but I see the same error whether using 2.4, 2.5, or 2.6.
To fix this I access the Auth settings through $this->_Collection
instead of $this->_registry
. I will submit a PR with these changes now, but please let me know if I'm doing something wrong on my end to run into this issue.
(P.S., I now realize I have only tested this on top of the FriendsOfCake/app-template project skeleton. I'm going to double-check this with a ๐ฆ install of Cake and report back here if I run into the same issue.)
Hi,
i started to work with this plugin on CakePHP3 and login works. But the userdata returning from facebook just includes username and id. it not includes i.e. email.
i didn't found a way to set fields-parameter for "/me?fields=..."
is there a way to get this data from your plugin?
I am getting this error after validation redirect from google. I am using cakephp 3.2
Error getting on this url - hybrid-auth/authenticated#
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.