Archived
1
0

Fixed adverts compiling, authorization and failsafe protocol

This commit is contained in:
Michael Gordeev
2019-12-05 17:49:53 +03:00
parent 0d3438d82d
commit 886aa1f9c0
7 changed files with 49 additions and 36 deletions
+9 -3
View File
@@ -11,6 +11,10 @@ using FoxTube.Core.Models;
using YouTube;
using System.Threading;
using Google.Apis.YouTube.v3;
using System.Net.Http;
using Google.Apis.Auth.OAuth2.Responses;
using Newtonsoft.Json;
using Google.Apis.Auth.OAuth2.Flows;
namespace FoxTube
{
@@ -41,15 +45,17 @@ namespace FoxTube
public static async Task<bool> AddUser()
{
Uri callbackUri = WebAuthenticationBroker.GetCurrentApplicationCallbackUri();
Uri requestString = AuthorizationHelpers.FormQueryString(ClientSecrets, callbackUri, Scopes);
Uri requestString = AuthorizationHelpers.FormQueryString(ClientSecrets, Scopes);
WebAuthenticationResult result = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.UseTitle, requestString, AuthorizationHelpers.Endpoint);
switch(result.ResponseStatus)
{
case WebAuthenticationStatus.Success:
UserCredential credential = await AuthorizationHelpers.ExchangeToken(ClientSecrets, new Regex(@"(?<=code=).?\w+").Match(result.ResponseData).Value);
string successCode = new Regex(@"(?<=code=)(.*?)(?=&)").Match(result.ResponseData).Value;
UserCredential credential = await AuthorizationHelpers.ExchangeToken(ClientSecrets, successCode);
CurrentUser = new User(credential);
PasswordVault passwordVault = new PasswordVault();
passwordVault.Add(new PasswordCredential("foxtube", CurrentUser.UserInfo.Id, credential.Token.RefreshToken));
return true;