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
+2 -6
View File
@@ -130,6 +130,7 @@
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
</PropertyGroup>
<ItemGroup>
<Compile Include="Helpers\Constants.cs" />
<Compile Include="Helpers\Extensions.cs" />
<Compile Include="Helpers\Feedback.cs" />
<Compile Include="Helpers\Inbox.cs" />
@@ -154,7 +155,7 @@
<Version>0.13.0</Version>
</PackageReference>
<PackageReference Include="ExtendedYouTubeAPI">
<Version>1.0.1</Version>
<Version>1.0.2</Version>
</PackageReference>
<PackageReference Include="Google.Apis.Auth">
<Version>1.42.0</Version>
@@ -189,11 +190,6 @@
<Name>Visual C++ 2015 Runtime for Universal Windows Platform Apps</Name>
</SDKReference>
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.Advertising">
<HintPath>..\..\..\..\NuGet\microsoft.advertising.xaml\10.1811.22001\SDK\Windows Kits\10\ExtensionSDKs\Microsoft.Advertising.Xaml\10.0\References\CommonConfiguration\neutral\Microsoft.Advertising.winmd</HintPath>
</Reference>
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
+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");
}
}