It is possible or not For this we have to implement OAuth 2.0 flow on the basis of which we will get a token and then on the basis of this token we generate the app password using the Gmail API endpoint.
Generate app password.
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Jithu ThomasRank #437 · 5.7K reputationPosted Apr 12, 2024, 4:34 AM EDT
No, it's not possible to generate an app password directly using the Gmail API and OAuth 2.0 flow. Here's why:
* **Design**: App passwords are designed as a user-controlled security mechanism for less secure applications that don't support OAuth. Granting access through the API would defeat the purpose of user control.
* **Security**: App passwords are 16-character, single-use credentials. OAuth provides a more secure method with tokens that can be scoped and revoked.
**Recommended Approach:**
For secure access to Gmail functionalities through your application, use OAuth 2.0. This method offers several advantages:
* **Security:** OAuth provides tokens with specific scopes, limiting application access to only the authorized data. Additionally, tokens can be revoked if needed.
* **Granular Control:** You can define the level of access granted to your application through scopes.
* **User Consent:** Users explicitly grant access to your application through the OAuth
Sourabh DhimanRank #2,987 · 483 reputationPosted Apr 12, 2024, 4:50 AM EDT
Thanks Jithu Thomas.