darkpool
darkpool

Reputation: 14651

Accessing a users google drive

I have a django site that uses Django allauth for users to log in using their google account and grant permission to their google drive. Once logged in, django-allauth saves a token for that user. This part all works correctly.

How do I now access the user's google drive (who has granted permission), to list the available files? Presumably this needs to use the token that was saved thanks to django-allauth.

I have installed the python google api client but am struggling to figure out how to use the user's token to list the content of their google drive.

There is a flask example here which im trying to modify for use in a django project utilizing django-allauth. The sign in flow works correctly, but django-allauth does not ensure that google drive access is requested. I've tried updating my settings as per this:

SOCIALACCOUNT_PROVIDERS = {
    "google": {
        "SCOPE": [
            "https://www.googleapis.com/auth/drive.metadata.readonly",
            "https://www.googleapis.com/auth/userinfo.profile",
        ],
        "AUTH_PARAMS": {"access_type": "offline"},
    }
}

Upvotes: 1

Views: 768

Answers (2)

bpt3
bpt3

Reputation: 21

For anyone reading this now, the current release of allauth does support API auth.

You need to provide the complete URL (e.g. https://www.googleapis.com/auth/drive) instead of just the scope name (e.g. email) in the SCOPE list for scopes that aren't in the default list within allauth.

Upvotes: 2

darkpool
darkpool

Reputation: 14651

There haven't been any answers posted so im just posting what I ended doing. It doesn't look like django-allauth can be used both for regular google authentication and api auth.

So for the time being a user first has to sign in to the site using their google account which is handled by django-allauth. Then once they're logged in they can select to grant access to their google drive which then kicks off a new auth flow for that (using the Google python api client)

Upvotes: 2

Related Questions