Search code examples
crongmail-apigoogle-authentication

Using Google auth for both user sign in and background services


We have a web application where we log users in with Google's auth2.

We also have crone jobs that are used to reply to certain emails through the gmail api.

Is the authorization for signing in and for gmail's api the same? If it is, how can we sign users out of the web app while still authorizing crone jobs?


Solution

  • If what you meant by signing is by using Google+ Sign-in, it says from this documentation:

    Why use Google for authentication?

    Providing OAuth 2.0 user authentication directly or using Google+ Sign-in reduces your development overhead. It also provides a trusted and secure login system that's familiar to users, consistent across devices, and removes the burden of users having to remember another username and password.

    Wherein Gmail uses the OAuth 2.0 protocol for authenticating a Google account and authorizing access to user data. This will be the same.

    At a high level, all apps follow the same basic authorization pattern:

    1. During development, register the application in the Google API Console.
    2. When the app launches, request that the user grant access to data in their Google account.
    3. If the user consents, your application requests and receives credentials to access the Gmail API.
    4. Refresh the credentials (if necessary).

    The difference is you will need to enable Gmail API for the credentials.

    Here's the details for server-side authentication.