如何在asp.net中使用Google云端硬盘进行身份验证,而无需复制/粘贴身份验证令牌

时间:2012-12-06 21:16:30

标签: asp.net authorization oauth-2.0

我试图在我的ASP程序中获取Google云端硬盘的授权码。我从Google API for .NET样本中编写了一些类似quickstart程序的代码:

private static IAuthorizationState GetAuthorization(NativeApplicationClient arg){
    // Get the auth URL:
    IAuthorizationState state = new AuthorizationState(
         new[] {DriveService.Scopes.Drive.GetStringValue() });
    state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
    Uri authUri = arg.RequestUserAuthorization(state);

    //Request authorization from the user (by opening a browser window):
    Process.Start(authUri.ToString());
    Console.Write("  Authorization Code: ");
    string authCode = Console.ReadLine();
    Console.WriteLine();

    // Retrieve the access token by using the authorization code:
    return arg.ProcessUserAuthorization(authCode, state);
}

我想通过打开一个弹出窗口来获取授权码,用户可以在此访问权限,在用户访问权限之后,返回代码。

0 个答案:

没有答案