adamwathan / eloquent-oauth-l5 Goto Github PK
View Code? Open in Web Editor NEWEloquent OAuth service provider and assets for Laravel 5
Eloquent OAuth service provider and assets for Laravel 5
Hi Adam
Just fyi, and maybe this is catered for already somewhere else but have just upgraded a site to Laravel 5.2 and had to change a line in:
vendor\adamwathan\eloquent-oauth-l5\src\Installation\InstallCommand.php
changed:
use Illuminate\Foundation\Composer
to
use Illuminate\Support\Composer;
Hope that helps someone!
Cheers
m
If a user logs in which hasn't logged in before I'm getting a ModelNotFoundException
thrown by vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php
.
The UserStore for this package deals a lot with the user aspect, so perhaps it should also catch errors like these?
I always getting the error:
FatalErrorException in routes.php line 19:
Call to undefined method AdamWathan\EloquentOAuthL5\EloquentOAuthServiceProvider::authorize()
app/Http/routes.php
<?php
...
Route::get('/github/authorize', function() {
return SocialAuth::authorize('github');
});
config/app.php
'providers' => [
...
AdamWathan\EloquentOAuthL5\EloquentOAuthServiceProvider::class,
],
'aliases' => [
...
'SocialAuth'=> AdamWathan\EloquentOAuthL5\EloquentOAuthServiceProvider::class,
],
I have done the installation via composer. Executed the installation and migration like described in the manual.
When the user has same email address ex. on facebook or on gmail account, and in the database the email address it's set unique, and the email address exists in DB the login not working correctly.
Gets an error, "Duplicate entry..." because the user already exists..
Any solution?
Problem
It looks like it is trying to pass through an Eloquent User of null in the registerOAuthManager function of EloquentOAuthServiceProvider.
It appears it's unable to create a UserStore it comes back null.
Steps to reproduce
Whoops, looks like something went wrong.
1/1
FatalThrowableError in Model.php line 852:
Fatal error: Class name must be a valid object or a string
in Model.php line 852
at Model->belongsTo(null, 'user_id') in UserStore.php line 25
at UserStore->findByIdentity(object(OAuthIdentity)) in Authenticator.php line 48
at Authenticator->getExistingUser('github', object(User)) in Authenticator.php line 27
at Authenticator->getUser('github', object(User)) in Authenticator.php line 18
at Authenticator->login('github', object(User), null) in OAuthManager.php line 24
at OAuthManager->login('github') in Facade.php line 216
at Facade::__callStatic('login', array('github')) in routes.php line 40
at RouteServiceProvider->{closure}('github')
at call_user_func_array(object(Closure), array('provider' => 'github')) in Route.php line 158
at Route->runCallable(object(Request)) in Route.php line 137
at Route->run(object(Request)) in Router.php line 703
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 64
........
Let me know if I'm missing something here, this is my first Laravel project and went to implement social logins, or if I'm being an idiot missing something here.
@adamwathan
Currently i am using your package for logging to soundcloud but facing above issue when call
SocialAuth::login('soundcloud');
Its working for google, github etc.
What is returned looks like:
/google/login?state=mWhYA2x84XXFqn54MAdJBqCEnwKbSWNG&code=4/d2YkPDB2NCddcF5u9YqZGqpaI35JGQNRnQs9ZK-fJ3A#
Seems 'state' parameter has not been handled properly because I get:
InvalidAuthorizationCodeException in SocialNorm.php line 52:
...
Update:
Actually it could be a kind of forgery attack simulation, because Google does not accept non-public return URLs and I'm obliged to 'fake' it with a public one stored in hosts file.
After upgrading to this package rather than the branch in the old project I'm getting this exception. This seems to originate from AuthManager.
After installing correctly the package and defining the provider and the facade, the command for publishing the package configuration php artisan eloquent-oauth:install
is not working in my L5.1 project. It says:
[InvalidArgumentException]
There are no commands defined in the "eloquent-oauth" namespace.
Also tried with: php artisan vendor:publish --provider="AdamWathan\EloquentOAuthL5\EloquentOAuthServiceProvider"
which responds: Nothing to publish for tag [].
Is the package ready for Laravel 5.1, or am I doing anything wrong?
Thanks in advance.
Please Adam, I am trying to authenticate a custom guard, and its not login in, instead redirecting me to the login route. I have another guard called admin and I am trying to use it with that
like doing something like SocialAuth::guard('admin')->login('facebook');
I am requesting added support for the Groupme API
Hi, first i need say thank you for this awesome package.
I'm using Laravel 5.1 fresh installation to test your package.
After authorization (authorization OK), when i'm redirected back to my app and i got a blank screen... nothing happens.
I try use dd() to debug, but always returns a blank screen, can you help-me?
My route
Route::get('facebook/authorize', function() {
return OAuth::authorize('facebook');
});
Route::get('facebook/login', function() {
//dd(OAuth::login('facebook'));
OAuth::login('facebook', function($user, $details) {
dd($details);
});
});
Thank you so much
Hi,
Any chance for twitter auth ?
Regards
Anty
I know it sounds very noob, but I can not perform the authentication routines using Controller.
When you try to login with an account that possesses registered email generates an SQL error.
Thanks,
Success!
It'd be awesome if you could pass the scope needed to the authenticate function.
I've looked at the code, but I haven't been able to find the place where the scope is passed to the github provider.
Could you point me in the rigth direction?
I followed the instructions exactly for installation of this package and used your route based setup from the video for the authorize and login resources, but I consistently get the following error:
Call to undefined method OAuth::authorize()
Being inside of the routes.php file, I am not inside of a namespace, although I also tried \OAuth::authorize()
as well. This is the relevant section of my route file:
Route::get('google/authorize', function() {
return OAuth::authorize('google');
});
Route::get('google/login', function() {
return OAuth::login('google', function ($user, $details) {
dd($details);
});
});
After banging my head for a bit, I tried renaming the facade alias in app.php to OAuth2
and changed my calls to use that instead, and it worked just fine.
I've confirmed that I do not have any other classes in my project or vendor folder with that same name. Doing a global grep of my project shows that the only class with that name is the facade itself (adamwathan/eloquent-oauth/src/Facades/OAuth.php), but it is namespaced so shouldn't cause a conflict and I don't have anything else with that name listed in my app.php aliases.
I also just tried upgrading my project to 5.1 since it was just released and have the same issue.
And of course, I have run composer du
until I am blue in the face just to be sure ;-)
Have you run into this? If so, do you know what would be causing something like that? I can leave my alias as something else, but it would be nice if I could get it to work as intended.
Hi @adamwathan,
Loving the relative ease of this package. Works like a charm for authentication. However, I'm having a bit of trouble trying to put together something that can call different endpoints once the access token is retrieved. What I have so far is the following:
What I think I need to have done:
Does that sound about right?
Additionally, will calling OAuthManager::login() trigger a new HTTP request if the access token is already stored in the database?
Thanks.
Hi Adam
I am a newcomer to Laravel 5 and was wondering if it was possible to use your package to simply register a user without going through any of the providers.
Currently I have the linkedin and facebook logins working smoothly and need to also be able to register and login a user just via their email/username/password.
Am I missing something simple perhaps?
Cheers
M
Hello ,there is an error for a facebook.
$user->name = $details->fullName;
Should be
$user->name = $details->full_name;
I'd like to be able to display a notification like "You are logged in using Facebook" on a profile page. And use that info in if statements as well. For example, they shouldn't be able to change their email address if they're using social login.
How do I check if they have an entry in oauth_identities without manually doing a query? Is there already a way using Auth::?
I'm currently using your package to facilitate logging in with social accounts. However, the login() function doesn't seem to recognize users that already exist in the database. This is the case when the user has previously logged in using email/password (for example with a gmail email). However, if they login later using Google, the function does not recognize the previous account, and makes a new one.
Is this normal? (If so, where exactly should I put the logic to use an existing user?).
Thanks in advance (and thanks for all your work).
Hi Adams,
just noticed that the wrapper doc still refer to the exception classes inside your package:
use \AdamWathan\EloquentOAuth\Exceptions\ApplicationRejectedException;
use \AdamWathan\EloquentOAuth\Exceptions\InvalidAuthorizationCodeException;
instead of
use SocialNorm\Exceptions\ApplicationRejectedException;
use SocialNorm\Exceptions\InvalidAuthorizationCodeException;
As in mentioned in #11 , I'm also facing the same issue while publishing the package configuration (after installing package, adding provider and facade)
On running php artisan eloquent-oauth:install
, it gives the following error:
[Symfony\Component\Console\Exception\CommandNotFoundException]
There are no commands defined in the "eloquent-oauth" namespace.
Also tried with: php artisan vendor:publish --provider="AdamWathan\EloquentOAuthL5\EloquentOAuthServiceProvider"
which responds: Nothing to publish for tag []
.
Am I missing something here?
P.S. I'm new to Laravel
I'm getting an error that eloquent-oauth-l5 doesn't recommend installing Laravel 5.1. Isn't this package compatible?
`<?php
namespace App\Http\Controllers;
use App\User;
use SocialAuth;
use Illuminate\Http\Request;
class SocialsController extends Controller
{
public function auth($provider)
{
return SocialAuth::authorize($provider);
}
public function auth_callback($provider)
{
SocialAuth::login($provider, function($user, $details){
$user->avatar = $details->avatar;
$user->email = $details->email;
$user->name = $details->full_name;
$user->save();
});
// $FBuser = User::find($username);
// Auth::login($FBuser);
return redirect('/home');
}
}`
this is my controller which handles the login process but it doesnt remembers the user. so how do i do it?? i have tried with the commented code but it showed error.
Hi, I have successfully implemented eloquent-oauth-l4 on my local machine.
My production server is on a shared host with PHP5.4.37, and so after some false trails, I have managed to install V0.1.2 (before support for PHP5.4 was withdrawn)
I now get this error when I try to 'php artisan dump-autoload' -
{"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"Class 'AdamWathan\EloquentOA
uthL4\EloquentOAuthServiceProvider' not found","file":"/home/jc/vendor/laravel/framework/src/Illuminate/Foun
dation/ProviderRepository.php","line":157}}
Have you any ideas to help?
I'm facing the same issue #23, this time with Google login, and Laravel 5.2 .
This is the error i get when i get redirected back to my app.
The redirect to facebook to approve the works perfect, but when i get redirected back to my website this gets spit out at me:
Client error:
GET https://graph.facebook.com/v2.4/me?access_token=EAAQalYXTmbsBAG1YokHVgUZCW6n0qwt7QKnd6D3ZAKgaJhRilpbHXmFhFgot4PvC16vABO2KU7X4pjp5vxWLjNPkJH5iogt8M5JicJ5QGHCZBHdSUGw7j9ZAQda8fG9jhZB4lY193hMMAh7zrx02FoMhmvum0GwoZD&fields=email,name,first_name,last_name,age_range,timezone` resulted in a 400 Bad Request
response:
{"error":{"message":"API calls from the server require an appsecret_proof argument","type":"GraphMethodException","code" (truncated...)`
What am i missing?
Hello Adam,
After the app authorization the callback URL(http://localhost:8000/facebook/login) the app does not store the user data of Facebook.
I followed all steps of your example in how to use Eloquent OAuth service provider, but I cannot see the problem.
Maybe is an update on Facebook that broke your code.
Greetings
Hi,
I followed the documentation and I'm stuck with the following:
SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: users.name (SQL: insert into "users" ("updated_at", "created_at") values (2015-06-27 17:23:57, 2015-06-27 17:23:57))
I tried with the Facebook provider. the authorise method is working, I authorise the App then I'm redirected back as expected...
*I have renamed the Alias to Social
(regarding the last issue)
public function facebookLogin()
{
try {
\Social::login('facebook');
} catch (ApplicationRejectedException $e) {
} catch (InvalidAuthorizationCodeException $e) {
}
// Current user is now available via Auth facade
$user = Auth::user();
dd($user);
}
Did I miss something?
Thank you :)
According to the readme, the facade (and exceptions) point to the eloquent-oauth
project rather than eloquent-oauth-l5
.
changing InstallCommand
line 21 to
if (starts_with(app()->version(), '5.1')) { $this->composer = app(Composer51::class); } else { $this->composer = app(Composer52::class); }
seems to help.
Facebook gives us the timezone (well, technically the timezone offset) but when I try to access $details->timezone
in OAuth::login('facebook', function($user, $details)
the timezone isn't there.
Am I missing something obvious?
I can use this for mobile right? like I make a get request to facebook/authorize
inside the client app.
@adamwathan
I have logout through my application normally or without login cancel from soundcloud
i am getting issue ApplicationRejectedException.
in query string => ?error=access_denied&error_description=The+end-user+denied+the+request.?error=access_denied&error_description=The+end-user+denied+the+request.
Hi Adam,
using the linkedIn provider and setting my scope to ['r_basicprofile', 'w_share']
, I asume I should receive more informations in the raw array, but I get the same result I add when my scope was set to 'w_share'
.
Iโm currently using the latest release on L5.1.
Am I missing something here?
Hi. I love this package but it is too tied to Laravel framework. When i look at the package dependencies i think we can move the following illuminate packages to their laravel spercific implimentation:
illuminate/auth, illuminate/session, illuminate/http and illuminate/routing. You can leave illuminate/database and illuminate/support in the main package. that way we can adapt the package in other frameworks like Slim.
thanks
facebook login is working but cannot get gender.
I am using this code
SocialAuth::login('facebook', function($user, $details) { dd( $details->raw()['gender'] ); });
Appreciate your help
I don't have much information to relate. I followed the video guide and the github instructions. But when I add a route such as:
Route::get('{provider}/authorize', function ($provider) {
return OAuth::authorize($provider);
});
And try to go to it I get Error 500. I have logging enabled but nothing shows up in the logs or on screen. I tried adding custom exception handler to display more info but that didn't seem to work.
I added debug code inside SocialNorm.php authorize() to see if it was at least being called (since I think that's what the route is ultimately calling) but the line is never reached. All other code on the site works.
Any ideas? Not sure if I'm doing something very stupid or it's some issue with the eloquent-oauth-l5 and maybe Laravel 5.3.
I'm using your package in my app and I'm also using laravel's soft delete (http://laravel.com/docs/5.1/eloquent#deleting-models).
When a soft-deleted user tries to login there's an error:
No query results for model [App\User].
I tried intercepting it with a little bit of code you posted in another issue:
$existing_user = User::where('email', $details->raw()['email'])->first();
if ($existing_user !== null && is_null($existing_user->deleted_at) == false) {
return view('banned');
}
But that doesn't work because even if I add an else to the if statement and return another view it will still give the error. I am quite of a newbie so apologies if this isn't a real issue, just figured posting wouldn't hurt.
Besides this little encounter I've had no problems with your package, good job!
First off, great add-on! It's been working very well up until I moved a domain from one google apps account to a new one. Basically, the domain was a add-on one original google app, not it's a stand alone on it's own google app.
That being said, when a user goes to sign in, they keep getting the following error thrown:
No query results for model [App\User].
At this point, I was able to get some users logged in by doing the following:
Not the prettiest, but seems to work. Of course the last user is not following this process and I cannot get a empty user created, or have them log in.
We are only using Google+ Oauth. I have revoked permission at Google Apps, that did not work. I have deleted the user and his oauth_identities row, I have deleted all session files, cleared cache, and he still cannot log in I'm at wits end. Here is my Auth code:
`
public function handleProviderCallback($provider)
{
try {
SocialAuth::login('google',function($user, $details){
//check to see if the user has a team email.
//if($this->teamCheck($details->raw()['email']) == false){
// throw new Exception;
//}
//explode full name from google
$name = explode(" ", $details->raw()['name']);
//check to see if user exists.
try {
$userExists = User::where('email', '=', $details->raw()['email'])->first();
}
catch(Exception $e){
dd($e);
}
//Very ugly code to save users. Needs to be refactored
if(!is_null($userExists)){
$userExists->email = $details->raw()['email'];
$userExists->first_name = $name[0];
$userExists->last_name = $name[1];
$userExists->avatar = $details->raw()['picture'];
try{
$userExists->save();
}
catch(Exception $e){
dd($e);
}
}
else{
$user->email = $details->raw()['email'];
$user->first_name = $name[0];
$user->last_name = $name[1];
$user->roles = 'N';
$user->avatar = $details->raw()['picture'];
try{
$user->save();
}
catch(Exception $e){
dd($e);
}
}
//check for admin
if( env('ADMIN_EMAIL') == $details->raw()['email'] ){
session()->put('is_admin', true);
}
});
} catch (ApplicationRejectedException $e) {
// User rejected application
} catch (InvalidAuthorizationCodeException $e) {
// Authorization was attempted with invalid
// code,likely forgery attempt
}
catch(Exception $e){
return redirect('auth/login');
}
`
Odd note, when on my local instance, I was able to create the user and log in with no problem.
Thanks,
Jay
There is assumption that project works with Illuminate\Database\Eloquent\Model in OAuthIdentity.php
Question:
Is there injection point or a way to override/replace it?
The only way I see is to fork and replace.
We have a database with emails of admins, so, we made a separate login page for them that validates if the email provided matchs with one in the table admins. Having the email and password, can we send them to one of the providers for authentication?
Hi there
I come to you because I really wanted to use a free option for social logins with sentinel. So, if you do find interesting to proceed with this work, I can start up by giving you my current error message (bacause I'm trying to insert a Sentinel User model in eloquent-oauth.php conf:
ErrorException in SessionGuard.php line 441: Argument 1 passed to Illuminate\Auth\SessionGuard::login() must be an instance of Illuminate\Contracts\Auth\Authenticatable, instance of Modules\User\Entities\Sentinel\User given, called in vendor/adamwathan/eloquent-oauth/src/Authenticator.php on line 21 and defined
@adamwathan Can you guide me?
Is it possible to tag the latest commit (share -> singleton), then it's possible that I can use the latest tag instead of dev-master commit.
Hi,
When trying to login with a user I get the following error:
this is the code I'm using:
Route::get('auth/authorize/{provider}', function($provider) {
return SocialAuth::authorize($provider);
});
Route::get('auth/login/{provider}', function($provider) {
try {
SocialAuth::login($provider, function($user, $details) {
$user->username = $details->nickname;
$user->name = $details->full_name;
$user->save();
});
} catch (ApplicationRejectedException $e) {
// User rejected application
dd('error1');
} catch (InvalidAuthorizationCodeException $e) {
// Authorization was attempted with invalid
// code,likely forgery attempt
print_r($provider);
dd($e);
}
// Current user is now available via Auth facade
$user = Auth::user();
dd($user);
return $user;
});
and the follwing is in my config/eloquent-oauth.php
<?php
use App\User;
return [
'model' => User::class,
'table' => 'oauth_identities',
'providers' => [
'facebook' => [
'client_id' => env('FACEBOOK_CLIENT_ID'),
'client_secret' => env('FACEBOOK_CLIENT_SECRET'),
'redirect_uri' => 'http://portal.latomme-g.be/api/v1/auth/login/facebook',
'scope' => [],
],
'google' => [
'client_id' => env('GOOGLE_CLIENT_ID'),
'client_secret' => env('GOOGLE_CLIENT_SECRET'),
'redirect_uri' => 'http://portal.latomme-g.be/api/v1/auth/login/google',
'scope' => [],
],
'github' => [
'client_id' => env('GITHUB_CLIENT_ID'),
'client_secret' => env('GITHUB_CLIENT_SECRET'),
'redirect_uri' => 'http://portal.latomme-g.be/api/v1/auth/login/github',
'scope' => [],
],
'linkedin' => [
'client_id' => '12345678',
'client_secret' => 'y0ur53cr374ppk3y',
'redirect_uri' => 'https://example.com/your/linkedin/redirect',
'scope' => [],
],
'instagram' => [
'client_id' => '12345678',
'client_secret' => 'y0ur53cr374ppk3y',
'redirect_uri' => 'https://example.com/your/instagram/redirect',
'scope' => [],
],
'soundcloud' => [
'client_id' => '12345678',
'client_secret' => 'y0ur53cr374ppk3y',
'redirect_uri' => 'https://example.com/your/soundcloud/redirect',
'scope' => [],
],
],
];
This problem exists for me for; Facebook, Google and Github (others I didn't try)
Problem 1
- Installation request for adamwathan/eloquent-oauth-l5 ^0.5.1 -> satisfiable by adamwathan/eloquent-oauth-l5[v0.5.1].
- adamwathan/eloquent-oauth-l5 v0.5.1 requires guzzlehttp/guzzle ^6.2.1 -> satisfiable by guzzlehttp/guzzle[6.2.1, 6.2.2, 6.2.x-dev] but these conflict with your requirements or minimum-stability.
Laravel ships with a services.php config that house an array of 3rd party, why not rely on that one in stead of the providers.php one?
So I was following the guide on how to setup Laravel 5 with your OAuth library.
However it seems that once I added 'AdamWathan\EloquentOAuthL5\EloquentOAuthServiceProvider' to my providers app config I was no longer able to run the php artisan command. I would be met with this error:
vagrant@homestead:/Code/Laravel/upkeep$ php artisan/Code/Laravel/upkeep$
[ReflectionException]
Class Illuminate\Foundation\Composer does not exist
vagrant@homestead:
I then dug down to the InstallCommand file and changed
use Illuminate\Foundation\Composer; to use Illuminate\Support\Composer;
I was then able to continue with the install process. ๐
Ninja edit
Welp. I think quite a lot changed with 5.2. I used php artisan make:auth to start with all the controllers / views. There appears to be big changes from the Laravel 5 repo you have uploaded (from what I can tell, this is actually my first Laravel project ever).
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.