-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthorization.cs
More file actions
60 lines (47 loc) · 1.55 KB
/
Copy pathAuthorization.cs
File metadata and controls
60 lines (47 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Tasks.v1;
using Google.Apis.Tasks.v1.Data;
using Google.Apis.Services;
using Google.Apis.Util.Store;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace WebApplication4.Controllers
{
public class Authorization
{
public TasksService service;
public Authorization()
{
System.Threading.Tasks.Task<TasksService> task = System.Threading.Tasks.Task.Run<TasksService>(async () => await RunAsync());
service = task.Result;
}
public async Task<TasksService> RunAsync()
{
var clientId = "792098940629-ocdlmose3reo78in6c61mpfaoj9htblp.apps.googleusercontent.com";
var clientSecret = "_9CVAqCDxfa-MX_0Hexd92Ge";
UserCredential credential;
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId = clientId,
ClientSecret = clientSecret
},
new[] { TasksService.Scope.Tasks, TasksService.Scope.TasksReadonly },
"user",
CancellationToken.None,
new FileDataStore("account.users"));
// Create the service.
var _service = new TasksService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Google Tasks Application",
});
return _service;
}
}
}