Google OAuth2: When and how to use refresh token

前端 未结 4 915
面向向阳花
面向向阳花 2021-01-07 01:46

I have an installed c# app with code working that gets the authorization code and exchanges it for an access token. I am storing off the refresh token. I know at some poin

4条回答
  •  离开以前
    2021-01-07 02:23

    When to use the refresh token:

    From what I understand you use the refresh token when you do not wish to authenticate your app each time it boots. This is extremely useful for debugging during application development (as manual authentication can get annoying after a while).

    How to use the refresh token:

    In the most basic sense:

    public static GOAuth2RequestFactory RefreshAuthenticate(){
        OAuth2Parameters parameters = new OAuth2Parameters(){
            RefreshToken = "",
            AccessToken = "",
            ClientId = "",
            ClientSecret = "",
            Scope = "https://spreadsheets.google.com/feeds https://docs.google.com/feeds",
            AccessType = "offline",
            TokenType = "refresh"
        };
        string authUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters);
        return new GOAuth2RequestFactory(null, "", parameters);
    }
    

    You would use this method in other code with a service, perhaps like this

    GOAuth2RequestFactory requestFactory = RefreshAuthenticate();
    SpreadsheetsService service = new SpreadsheetsService("");
    service.RequestFactory = requestFactory;
    

    Hope this helps!

提交回复
热议问题