1 回答

TA貢獻1744條經驗 獲得超4個贊
重定向uri問題
您請求中的重定向 uri 是http://127.0.1:59693/authorize
您尚未在授權重定向 Uris 下添加的。
您不能只添加任何重定向 uri??蛻舳藥熳约簶嫿ㄟ@個 url??偸侨绱?/p>
host:port/authorize
申請類型
您可以創建多種類型的客戶端,這些客戶端旨在與不同類型的應用程序一起使用。用于連接這些客戶端的代碼也不同。
已安裝的應用程序 - 安裝在用戶機器上的應用程序
Web 應用程序 - 托管在通過 Web 瀏覽器連接到用戶的 Web 服務器中的應用程序。
已安裝的應用程序
您正在使用GoogleWebAuthorizationBroker.AuthorizeAsync
它是為與已安裝的應用程序一起使用而設計的。瀏覽器窗口將在機器本身上打開。如果您嘗試將其托管在 Web 服務器上,瀏覽器將嘗試在服務器上打開并且不會顯示給用戶。
網絡應用
您應該關注Web 應用程序并使用GoogleAuthorizationCodeFlow
using System;
using System.Web.Mvc;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Auth.OAuth2.Flows;
using Google.Apis.Auth.OAuth2.Mvc;
using Google.Apis.Drive.v2;
using Google.Apis.Util.Store;
namespace Google.Apis.Sample.MVC4
{
public class AppFlowMetadata : FlowMetadata
{
private static readonly IAuthorizationCodeFlow flow =
new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
{
ClientSecrets = new ClientSecrets
{
ClientId = "PUT_CLIENT_ID_HERE",
ClientSecret = "PUT_CLIENT_SECRET_HERE"
},
Scopes = new[] { DriveService.Scope.Drive },
DataStore = new FileDataStore("Drive.Api.Auth.Store")
});
public override string GetUserId(Controller controller)
{
// In this sample we use the session to store the user identifiers.
// That's not the best practice, because you should have a logic to identify
// a user. You might want to use "OpenID Connect".
// You can read more about the protocol in the following link:
// https://developers.google.com/accounts/docs/OAuth2Login.
var user = controller.Session["user"];
if (user == null)
{
user = Guid.NewGuid();
controller.Session["user"] = user;
}
return user.ToString();
}
public override IAuthorizationCodeFlow Flow
{
get { return flow; }
}
}
}
- 1 回答
- 0 關注
- 101 瀏覽
添加回答
舉報