2013-05-03 91 views
5

我正在嘗試使用gmail smtp使用oauth 2.0。我使用aspose.dll來使用授權url請求訪問令牌。當我收到響應時,我不會收到刷新令牌。如果以前過期,則無法請求新的訪問令牌。所以我想每次我的應用程序需要獲取訪問令牌。如果授權碼過期,那麼我不能採用這種方法。是否授權代碼gmail oauth2有效期

gmail oauth2授權碼是否過期?

回答

7

Google的OAuth 2.0確實提供刷新標記!這裏的link解釋了各種流程並討論了應用程序爲所有場景獲取訪問權限和可選的刷新令牌。

授權碼DOES expire!這就是OAuth協議規定的。我無法在Google上查到確切的時間段,但我確實知道,對於Facebook),授權碼將在10分鐘內過期(請參閱鏈接中的更改12月5日)。
刷新令牌已經可用於您的用例。如果授權碼持續存在,Refresh令牌和授權碼之間會有什麼不同。

我建議你查看你正在使用的Aspose庫的文檔。

PS - 授權碼/訪問令牌/刷新令牌全部由中央Google授權服務器頒發!所以,我們正在談論谷歌的授權代碼,正如我所說,代碼會過期。

祝你好運!

編輯 - 添加更多的信息對您

 The authorization code generated by the 
    authorization server. The authorization code MUST expire 
    shortly after it is issued to mitigate the risk of leaks. A 
    maximum authorization code lifetime of 10 minutes is 
    RECOMMENDED. The client MUST NOT use the authorization code 
    more than once. If an authorization code is used more than 
    once, the authorization server MUST deny the request and SHOULD 
    revoke (when possible) all tokens previously issued based on 
    that authorization code. The authorization code is bound to 
    the client identifier and redirection URI. 

來源 - http://tools.ietf.org/html/draft-ietf-oauth-v2-31
科 - 4.1.2

+0

感謝,你知道任何.NET庫,會得到我可以訪問和祕密令牌。 – 2013-05-07 04:56:36

+0

恐怕不是。但谷歌確實提供了OAuth自己的dotnet API,爲什麼不使用它。 http://code.google.com/p/google-api-dotnet-client/wiki/OAuth2這個鏈接也有一些樣本,你可能想要通過他們的 – divyanshm 2013-05-07 04:59:34

+0

,但他們沒有提到有關獲取訪問和刷新令牌的任何地方都。 – 2013-05-07 05:51:32