Fixed adverts compiling, authorization and failsafe protocol
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user