Archived
1
0

Started to implement an Google authentication

This commit is contained in:
Michael Gordeev
2018-04-21 15:15:15 +03:00
parent 488cce915e
commit a7098448ed
2 changed files with 48 additions and 2 deletions
+2 -2
View File
@@ -67,8 +67,8 @@
Width="50" Height="50" Background="#00000000" RelativePanel.LeftOf="searchField"> Width="50" Height="50" Background="#00000000" RelativePanel.LeftOf="searchField">
<Button.Flyout> <Button.Flyout>
<MenuFlyout> <MenuFlyout>
<MenuFlyoutItem Text="Sign in with existing account"/> <MenuFlyoutItem Text="Sign in with existing account" Name="signIn" Click="signIn_Click"/>
<MenuFlyoutItem Text="Create a new Google account"/> <MenuFlyoutItem Text="Create a new Google account" Name="createAccount" Click="createAccount_Click"/>
</MenuFlyout> </MenuFlyout>
</Button.Flyout> </Button.Flyout>
</Button> </Button>
+46
View File
@@ -20,6 +20,15 @@ using Windows.UI.Notifications;
using Windows.UI.Xaml.Media.Imaging; using Windows.UI.Xaml.Media.Imaging;
using Windows.Storage; using Windows.Storage;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using Google.Apis.Upload;
using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data;
using System.Threading.Tasks;
using System.Threading;
using Google.Apis.Util.Store;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace FoxTube namespace FoxTube
@@ -284,5 +293,42 @@ namespace FoxTube
{ {
AccountManagement.IsOpen = true; AccountManagement.IsOpen = true;
} }
private void createAccount_Click(object sender, RoutedEventArgs e)
{
Process.Start("https://accounts.google.com/signup/");
}
private void signIn_Click(object sender, RoutedEventArgs e)
{
LogIn().Wait();
}
private async Task LogIn()
{
UserCredential credential;
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(@"ms-appx:///client_secrets.json"));
Debug.WriteLine("Exception accured after opening a stream");
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(await file.OpenStreamForReadAsync()).Secrets,
new[] { YouTubeService.Scope.Youtube },
"user",
CancellationToken.None,
new FileDataStore(this.GetType().ToString())
);
Debug.WriteLine("200 OK");
/*using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
{
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
new[] { YouTubeService.Scope.Youtube },
"user",
CancellationToken.None,
new FileDataStore(this.GetType().ToString())
);
}*/
}
} }
} }