Google Web Authorization broker creates secret uri

I want to create UserCredentials for my program, and the signature of this task seems

Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.AuthorizeAsync(
(Uri clientSecretsUri, IEnumerable<string> scopes, string user, CancellationToken taskCancellationToken);

All the tutorials that I found only created the ClientSecrets class and passed this as an argument, unfortunately this class does not have a .ToUri () method. I also cannot find any documentation on how this uri should be built. So, given that I obviously have my client ID and secret (and redirect uri if necessary), how can I create the uri needed for this authorization?

+4
source share
2 answers

I assume that you are developing for a universal Windows platform? Then this will work:

neosapien, client_secrets.json .

Content.

( <ProjectDirectory>/Assets/client_secrets.json) :

await GoogleWebAuthorizationBroker.AuthorizeAsync( 
                    new Uri("ms-appx:///Assets/client_secrets.json"),
                    new[] {CalendarService.Scope.Calendar, DriveService.Scope.Drive},
                    "user",
                    CancellationToken.None)
+7

Google .json Credentials API Auth .

.json , , .

:

  • using Google.Apis.Services // for BaseClientService
  • using Google.Apis.Util.Store // for FileDataStore
  • using System.Threading // for CancellationToken.None
  • using System.Reflection // for accessing the embedded resource of the json file
  • Using Google.Apis.Auth.OAuth2
  • google; , Google.Apis.Calendar Google.Apis.Gmail .

:

UserCredentials credentials;
CalendarService calendarService

, Google API:

try 
{
     GoogleWebAuthorizationBroker.Folder = "Tasks.Auth.Store";
     credentials = await GoogleWebAuthorizationBroker.AuthorizeAsync(
          GoogleClientSecrets.Load({file name or stream}).Secrets,
          new[] {
          GmailService.Scope.GmailCompose,
          CalendarService.Scope.Calendar,
          Google.Apis.Plus.v1.PlusService.Scope.UserinfoEmail },
          "user", CancellationToken.None,
          new FileDataStore("AppDataFolderName"));
} ...

.json , try/catch using (var cryptoStream = Encryption.ReadJson()) block followed by GoogleClientSecrets.Load(cryptoStream).Secrets, , .

gmail, Google, , G +. , API- Google Developers Console.

, . :

calendarService = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = credentials,
ApplicationName = "My Application"
});

.

, , . , Google | Daimto

0

All Articles