Search code examples
oauth-2.0google-oauthwhmcs

"Error 403: access_denied" when usign Google OAuth


I am trying to understand the basic logics for receiving GMail emails with Google OAuth. I see this document Authorizing Your App with Gmail

Now I follow the instructions in Setting Up POP3 Importing with OAuth via Google to setup POP3 with Google OAuth.

I login one Google account(Account1) and then in Google Cloud, create the Google App and OAuth Client ID.

Then I start connect to GMail account(Account2) with the web application(WHMCS). When connecting, it asks me to choose an account that create the app, so I choose Account1. But get the following error:

Error 403: access_denied The developer hasn’t given you access to this app.

Thus I am a bit confused. Since Account1 is used to create the app and OAuth Client ID, it should be able to access the app when I choose Account1, but the app will not be able to access the data in Account2. Or does the App in the error message means Gmail, not the app I created in Google Cloud?

Should I use Account2 to create the app for receiving emails in Account2? If yes, then for each Gmail account, should I create a separate app accordingly?

Update

Now I try to do as follows:

  1. Use Account3(The admin of Google Workspace) to create the Cloud Project, Consent Window, Client ID, etc.
  2. Then when connecting from WHMCS on our domain datanumen.com, it asks me to choose the account, I choose Account3, and then see a new window as below:

enter image description here

I then select "Allow" button, but then see the following error:

Connection unsuccessful. Please close this window and try again.

Update

I try several times. And find the first time will be successful. I forget enable POP3 in my Gmail account. After enabling it, everything is fine.


Solution

  • I am a bit confused as to what you are trying to do here.

    You created a project on Google cloud console and created client id and client secret for the authorization of your project.

    All this does is create a project that will be allowed to use Oauth2 to request authorization of a user to access their data.

    If I understand what WHMCS is trying to do. Its going to let you use your client id and client secret to request access of a user to access their data.

    So when it asks you to authorize a user this is the user whos data you want access to. That user must be added as a test user over on Google cloud console for the project that you created.

    enter image description here

    The project you create on google cloud console is still in the testing phase. Each user you want to allow to test your application must be added as a test user. Other wise only the owner of the project can test the applicaiton.

    To fix this issue for me was this simple:

    1. Go to https://console.developers.google.com/
    2. open the project in question.
    3. Click "OAuth consent screen" on the left.
    4. Under "Test users" there is a button called "+ ADD USERS"
    5. Type the email of the account you will be testing with, press enter, then click save.
    6. It should work now

    It seems like they updated this recently because last year I did not have to do this.

    workspace

    The issue you may be having is that if you created this project on a workspace account then i suspect only workspace domain users are going to be able to authorize it. It cant be authorized by someone on the standard google domain. So try with a workspace domain user. The same may go the other way I have never tried tbh. I tend to keep workspace within its domain.