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
+8
View File
@@ -0,0 +1,8 @@
namespace FoxTube.Core.Helpers
{
public static class Constants
{
public static string ApplicationId => "9ncqqxjtdlfh";
public static string AdsId => "1100044398";
}
}
+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;
+8 -5
View File
@@ -1,6 +1,7 @@
using Microsoft.Advertising.WinRT.UI;
using System;
using System;
using System.Collections.Generic;
using Windows.ApplicationModel.Core;
using Windows.Security.Credentials;
namespace FoxTube.Core.Helpers
{
@@ -23,15 +24,17 @@ namespace FoxTube.Core.Helpers
/// </summary>
/// <param name="args">Parameters which will be provided to new application instance</param>
public static async void RestartApp(string args) =>
await CoreApplication.RequestRestartAsync(args);
await CoreApplication.RequestRestartAsync(args ?? "");
public static void InitializeFailsafeProtocol()
{
Metrics.AddEvent("Failsafe protocol initiated");
Settings.ResetSettings();
PasswordVault passwordVault = new PasswordVault();
IReadOnlyList<PasswordCredential> credentialEntries = passwordVault.RetrieveAll();
foreach (PasswordCredential credential in credentialEntries)
passwordVault.Remove(credential);
RestartApp();
}
public static NativeAdsManagerV2 AdManager => new NativeAdsManagerV2("9ncqqxjtdlfh", "1100044398");
}
}