Google Drive Api - MVC IDataStore

I am using MVC sample code from google to connect to google drive. However, I want to implement my own IDataStore

so that I can store user credentials in my database.

With the FileStorage sample, everything works fine and I get a Token and a RefreshToken and what's more, it automatically refreshes the tokens when it expires.

The implementation IDataStore

looks simple:

public class MyDataStore : IDataStore
{
    public Task ClearAsync()
    {
        ...
    }

    public Task DeleteAsync<T>(string key)
    {
        ...
    }

    public Task<T> GetAsync<T>(string key)
    {
        ...
    }

    public Task StoreAsync<T>(string key, T value)
    {
        ...
    }
}

      

So in StoreAsync

I store the credentials in my database, and in GetAsync

I get it from the database.

But strange when using this I get access_token

but not refresh_token

returned from google.

I tried to search from samples using custom IDataStore

, but I can't find anything.

Any ideas?

Thank you so much

+3


source to share


1 answer


Taking into account @ gui47's comment, I was looking for how to add the access_type parameter and I found another post from fooobar.com/questions/2114188 / ... using the solution:

internal class OfflineGoogleAuthorizationCodeFlow : GoogleAuthorizationCodeFlow
{
    public OfflineGoogleAuthorizationCodeFlow(GoogleAuthorizationCodeFlow.Initializer initializer) : base(initializer) { }

    public override AuthorizationCodeRequestUrl CreateAuthorizationCodeRequest(string redirectUri)
    {
        return new GoogleAuthorizationCodeRequestUrl(new Uri(AuthorizationServerUrl))
        {
            ClientId = ClientSecrets.ClientId,
            Scope = string.Join(" ", Scopes),
            RedirectUri = redirectUri,
            AccessType = "offline",
            ApprovalPrompt = "force"
        };
    }
};

      



Many thanks

+1


source







All Articles