Accessing Gmail API through Azure Function hosted in Portal

Japnam Singh 71 Reputation points
2022-09-15T21:00:26.37+00:00

Hi,

I am trying to implement Azure function to get the token from Google oauth v2 and retrieve all the messages in the inbox.

I have added google authentication under authentication but I am not sure how to add scope to it, as my token is getting generated and giving this error when I call the endpoint(https://gmail.googleapis.com/gmail/v1/users/me/messages) giving 403
request has insufficient scopes 241662-scopes-cant-add.png241509-postman1.png

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
0 comments No comments
{count} vote

Accepted answer
  1. MuthuKumaranMurugaachari-MSFT 22,441 Reputation points Moderator
    2022-09-22T16:32:44.033+00:00

    @Anonymous Thank you for reaching out to Microsoft Q&A. Sorry for the delay in response.

    As per docs: Add Google information to your application and message you saw in the portal, you would need to define scopes in Provider's registration portal (Google) and App Service or Functions can request scope at login time. Meaning you don't need to add scope in Functions app (or App Service). Please follow the docs and validate and if you have any questions, feel free to reach out. Correct me if my understanding is incorrect.

    Based on endpoint: https://gmail.googleapis.com/gmail/v1/users/me/messages you shared, you need any of the following scopes for list operation according to Gmail API - List (also refer Gmail API - Get) and I saw you appear to have gmail.modify scope. Since the request is failing directly from POSTMAN to Google API(s), I would recommend you reach out to Provider (Google) for the failure.

    243899-image.png

    I hope this answers your question and if you face any issue from Azure Functions app, please share the details. I would be happy to assist you.

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.