Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't login with multiple users? #67

Closed
mcgregorjamie opened this issue Apr 30, 2019 · 12 comments
Closed

Can't login with multiple users? #67

mcgregorjamie opened this issue Apr 30, 2019 · 12 comments

Comments

@mcgregorjamie
Copy link

mcgregorjamie commented Apr 30, 2019

I have tried setting GOOGLE_ALLOW_MULTITPLE_CREDENTIALS=true in the env file (and refreshing config cache) as well as hardcoding 'allow_multiple_credentials' => true in config/gmail.php.

But when I login as a User A in one browser, then log in as User B in a different browser, I can only see the data for User A. If I take a look at storage/app/gmail/tokens/ there's only one gmail-json file and when I open it, only the details for User A are in there.

I'm sure I'm missing something obvious here, but hoping someone can help!

@dacastro4
Copy link
Owner

@mcgregorjamie Can you tell me if the file is named gmail-json-?

@mcgregorjamie
Copy link
Author

Yes the file is gmail-json.json

@dacastro4
Copy link
Owner

Hopefully, thanks to @nasatome, this issue is solved.

@mcgregorjamie
Copy link
Author

@dacastro4 Still having the same issue unfortunately :(

@dacastro4 dacastro4 reopened this May 1, 2019
@dacastro4
Copy link
Owner

@mcgregorjamie

  1. did you log in before changing allow_multiple_credentials to true? if so, try to removing the file and trying it again.
  2. Is the route where you have all the user information inside of a group with the auth middleware?

@mcgregorjamie
Copy link
Author

mcgregorjamie commented May 1, 2019

@dacastro4

  1. I've tried removing the file but the same thing happens.
  2. Sorry, not sure I understand. Which route needs to be inside a group with the auth middleware? I followed the readme.md so my routes look like this:
Route::get('/oauth/gmail', function (){
    return LaravelGmail::redirect();
});

Route::get('/oauth/gmail/callback', function (){
    LaravelGmail::makeToken();
    return redirect()->to('/');
});

Route::get('/oauth/gmail/logout', function (){
    LaravelGmail::logout(); //It returns exception if fails
    return redirect()->to('/');
});

@dacastro4
Copy link
Owner

@mcgregorjamie that may be the problem. Enclose that code inside

Route::group(['middleware' => ['auth']], function() {
    //
});

@mcgregorjamie
Copy link
Author

That has fixed it, thank you so much for all of your help!

@dacastro4
Copy link
Owner

@mcgregorjamie No problem!

@nasatome
Copy link
Contributor

nasatome commented May 1, 2019

Sorry to open this problem again, but I think we should put in the documentation that to use multiple users, the user should be logged in with laravel previously (since the user's id is used to save the json)

I was thinking of some method of using multiple users without needing the user ID (which is standard and repeatable) but I can not think of any at this time, and in the current state of laravel-gmail to throw an error if the person has enabled in true "allow_multiple_credentials" and the user is not logged.

Allowing multiple users to be used without the user being logged in (using an id, such as the person's email but hashed SHA-2 + algorithm to avoid collisions) would allow oauth2.0 to even be used as a system login and completely replace the use of other plugins such as "Laravel Socialite" for particular uses of Google

I do not know, they are just crazy ideas in my mind.

going back to the starting point, for now, @dacastro4 , what do you think of the action of placing in the documentation that it is necessary for the user to be authenticated with laravel in order for the multiple credentials to work?

@alalfakawma
Copy link

@mcgregorjamie that may be the problem. Enclose that code inside

Route::group(['middleware' => ['auth']], function() {
    //
});

Can I use the auth middleware for api calls?

@dacastro4
Copy link
Owner

@alalfakawma you should be able to use it with the auth:api middleware

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants