您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Google Calendar API v3-使用硬编码的凭据进行身份验证

Google Calendar API v3-使用硬编码的凭据进行身份验证

您将需要同时使用开发者密钥(API密钥)和OAuth2。开发人员密钥对谁编写软件进行身份验证,并用于配额之类的事情,配额是基于每个开发人员而不是每个用户的。OAuth2用于用户身份验证,将需要访问非公共日历。

OAuth2具有续订令牌,您可以从中生成会话令牌,这意味着您无需屏幕刮OAuth屏幕即可进行身份验证。为此,我将编写一个小的命令行应用程序,或者使用一个关闭PHP页面

private IAuthorizationState CreateAuthorization(NativeApplicationClient arg)
 {
   // Get the auth URL:
   IAuthorizationState state = new AuthorizationState(new[] { AdsenseService.Scopes.AdsenseReadonly.GetStringValue() });
   state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
   if (refreshToken.IsNotNullOrEmpty()) // refreshToken you stored in step 4
   {
     try
     {
       state.RefreshToken = refreshToken;
       if (arg.RefreshToken(state))     // This is calling out to the OAuth servers with the refresh token getting back a session token, returns true if successful.
       {
         if (state.RefreshToken != refreshToken) // if the refresh token has changed, save it.
         {
           PersistRefreshToken(authorization.RefreshToken);
         }
         return this.authorization = state; // Retain the authorization state, this is what will authenticate your calls.
       }
     }
     catch (ProtocolException ex) {...}

现在可以将已更新的AuthorizationState用来验证对API的调用。此状态可以使用很多次,直到到期,然后可以刷新。当您以自己(而非用户)身份验证应用程序时,所有会话都可以共享此AuthorizationState。当前的AuthorizationState和刷新令牌都应安全地保存在您的服务器上,并且永远不要发送给客户端,如果您将它们作为响应的一部分发送,则您的客户端将具有与代码应用程序相同的特权

Go 2022/1/1 18:14:14 有618人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶