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

Multiple user login not working #270

Open
kstmostofa opened this issue Dec 20, 2023 · 3 comments
Open

Multiple user login not working #270

kstmostofa opened this issue Dec 20, 2023 · 3 comments

Comments

@kstmostofa
Copy link

I am using setUserId to set the token but somehow login is not working.

below are my code sample

public function callback() { $userId = 'user'. rand(1, 100); LaravelGmail::setUserId($userId)->makeToken(); return redirect()->to('/'); }

code

Thanks in advance

@gnucasher
Copy link

Your code sample is not going to work the way you expected. In order for it to work, you have to save the userID somewhere else, which was generated randomly so that you can retrieve this ID later on (for further requests such as list mails, read mails, etc.)

The package was created to allow multiple credentials; however, quite in a different manner - it supposed that the application that uses the package has multiple users, and thus, it saves the Google API responses in JSON files according to the ID of the currently logged-in user (or whichever other user in that system).

That is logically understandable. However, it left out some edge cases:

  • What if one user has multiple Gmail addresses?
  • What if different users under the same system use some common Gmail addresses?

The package itself does not acquire any userID from Google response, at least not before executing makeToken(). It is not impossible to modify the sample codes to get the information you need (whatever is necessary to feed the $userID), but I don't want to make things complicated.

The quick dirty "workaround" code is as follows:

Add this line to the makeToken() method in vendor/dacastro4/laravel-gmail/src/GmailConnection.php, under $this->emailAddress = $me->emailAddress;

$this->userId = $this->_config['gmail.allow_multiple_credentials'] ? $me->emailAddress : null;

inside callback() method, you only need to use the basic sample code provided:

LaravelGmail::makeToken();

The code will save response data to a JSON file with a logged-in email address. For eg.; instead of saving to gmail-json-1.json, gmail-json-2.json..., it will save to gmail-json-someone@gmail.com.json; Later on, when calling further methods, you only need to specify the logged in email address as userID, then you are all set.

By pointing out some edge cases above, I also proposed that it is necessary to change the code to archive "true" multiple credentials by using it. Developers will not have to update the package manually for such "tweaks". This is not the perfect solution, it is just the quickest one, because it still leaves the second edge case listed above.

For system with multiple users, the correct way to save response filename should be:
gmail-json-(systemUserID)-(loggedInEmailAddress).json

@kstmostofa
Copy link
Author

@gnucasher Thanks for your reply
I have fixed my issue with a different approach.
anyway thanks for your reply

@umarzahid028
Copy link

Hi @kstmostofa,

I'm glad to hear that you've resolved your issue with a different approach! I'm always interested in learning new solutions. Would you mind sharing the details of your approach? I'd love to know more about how you tackled the problem.

Thanks,
Umar

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

3 participants