5
Google.Apis.Auth.OAuth'u C# Webforms ile nasıl kullanabileceğinizi gösteren basit bir örnek var mı? Sadece MVC'leri bulabilirim.Google.Apis.Auth.OAuth
Google.Apis.Auth.OAuth'u C# Webforms ile nasıl kullanabileceğinizi gösteren basit bir örnek var mı? Sadece MVC'leri bulabilirim.Google.Apis.Auth.OAuth
Bir süre oldu ama bu biri için yararlı olabileceğini düşündük:
GoogleFlowMetaData:
public class GoogleFlowMetaData
{
private static readonly IAuthorizationCodeFlow flow =
new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
{
ClientSecrets = new ClientSecrets
{
ClientId = "your client ID",
ClientSecret = "your client secret"
},
Scopes = new[] { CalendarService.Scope.Drive/*or any service you want*/ },
DataStore = new FileDataStore("Drive.Api.Auth.Store")
});
public IAuthorizationCodeFlow Flow
{
get { return flow; }
}
}
AuthorizationCodeApp: İstediğiniz her yerde
şimdipublic class AuthorizationCodeApp : AuthorizationCodeWebApp
{
private readonly GoogleFlowMetaData flowData;
private readonly string redirectUri;
private readonly string state;
private readonly string userID;
public GoogleFlowMetaData FlowData { get { return flowData; } }
public AuthorizationCodeApp(GoogleFlowMetaData flowData, string redirectUri, string state, string userID):base(
flowData.Flow,redirectUri,state)
{
this.redirectUri = redirectUri;
this.state = state;
this.userID = userID;
}
public Task<AuthResult> AuthorizeAsync(CancellationToken taskCancellationToken)
{
return base.AuthorizeAsync(userID, taskCancellationToken);
}
}
bir zaman uyumsuz görevi çalıştırmak için gibi bir şey tanımlamak için:
public async Task<string> IndexAsync(CancellationToken cancellationToken)
{
var result = await new AuthorizationCodeApp(new GoogleFlowMetaData(), "http://localhost:4356/API/GAuth","","beebee").
AuthorizeAsync(cancellationToken);
if (result.Credential != null)
{
var service = new DriveService(new BaseClientService.Initializer
{
// YOUR CODE SHOULD BE HERE..
});
}
else
{
return result.RedirectUri;
}
}
Yukarıdaki işlevi çağırmak için 210
(
var cancelToken = new CancellationTokenSource();
var z = Task.Factory.StartNew(() => IndexAsync(cancelToken.Token));