Skip to content

Commit 24bb3d3

Browse files
committed
Finished UWP Example using protocol registration - Docs TODO
1 parent d095a5a commit 24bb3d3

22 files changed

Lines changed: 520 additions & 240 deletions

File tree

‎SpotifyAPI.Web.Auth/EmbedIOAuthServer.cs‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -80,30 +80,6 @@ public Task Stop()
8080
return Task.CompletedTask;
8181
}
8282

83-
public Uri BuildLoginUri(LoginRequest request)
84-
{
85-
Ensure.ArgumentNotNull(request, nameof(request));
86-
87-
StringBuilder builder = new StringBuilder(SpotifyUrls.Authorize.ToString());
88-
builder.Append($"?client_id={request.ClientId}");
89-
builder.Append($"&response_type={request.ResponseTypeParam.ToString().ToLower()}");
90-
builder.Append($"&redirect_uri={HttpUtility.UrlEncode(BaseUri.ToString())}");
91-
if (!string.IsNullOrEmpty(request.State))
92-
{
93-
builder.Append($"&state={HttpUtility.UrlEncode(request.State)}");
94-
}
95-
if (request.Scope != null)
96-
{
97-
builder.Append($"&scope={HttpUtility.UrlEncode(string.Join(" ", request.Scope))}");
98-
}
99-
if (request.ShowDialog != null)
100-
{
101-
builder.Append($"&show_dialog={request.ShowDialog.Value}");
102-
}
103-
104-
return new Uri(builder.ToString());
105-
}
106-
10783
public void Dispose()
10884
{
10985
Dispose(true);

‎SpotifyAPI.Web.Auth/IAuthServer.cs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ public interface IAuthServer : IDisposable
1212
Task Start();
1313
Task Stop();
1414

15-
Uri BuildLoginUri(LoginRequest request);
16-
1715
Uri BaseUri { get; }
1816
}
1917
}

‎SpotifyAPI.Web.Auth/Models/Request/LoginRequest.cs‎

Lines changed: 0 additions & 26 deletions
This file was deleted.

‎SpotifyAPI.Web.Examples/Example.CLI.CustomHTML/Program.cs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ public static async Task Main()
2626

2727
_server.AuthorizationCodeReceived += OnAuthorizationCodeReceived;
2828

29-
var request = new LoginRequest(clientId, LoginRequest.ResponseType.Code)
29+
var request = new LoginRequest(_server.BaseUri, clientId, LoginRequest.ResponseType.Code)
3030
{
3131
Scope = new List<string> { UserReadEmail }
3232
};
3333

34-
Uri url = _server.BuildLoginUri(request);
34+
Uri uri = request.ToUri();
3535
try
3636
{
37-
BrowserUtil.Open(url);
37+
BrowserUtil.Open(uri);
3838
}
3939
catch (Exception)
4040
{
41-
Console.WriteLine("Unable to open URL, manually open: {0}", url);
41+
Console.WriteLine("Unable to open URL, manually open: {0}", uri);
4242
}
4343

4444
Console.ReadKey();

‎SpotifyAPI.Web.Examples/Example.CLI.PersistentConfig/Program.cs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,19 @@ private static async Task StartAuthentication()
6565
await _server.Start();
6666
_server.AuthorizationCodeReceived += OnAuthorizationCodeReceived;
6767

68-
var request = new LoginRequest(clientId, LoginRequest.ResponseType.Code)
68+
var request = new LoginRequest(_server.BaseUri, clientId, LoginRequest.ResponseType.Code)
6969
{
7070
Scope = new List<string> { UserReadEmail, UserReadPrivate, PlaylistReadPrivate }
7171
};
7272

73-
Uri url = _server.BuildLoginUri(request);
73+
Uri uri = request.ToUri();
7474
try
7575
{
76-
BrowserUtil.Open(url);
76+
BrowserUtil.Open(uri);
7777
}
7878
catch (Exception)
7979
{
80-
Console.WriteLine("Unable to open URL, manually open: {0}", url);
80+
Console.WriteLine("Unable to open URL, manually open: {0}", uri);
8181
}
8282
}
8383

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
<Application
2-
x:Class="UWP.App"
3-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5-
xmlns:local="using:UWP">
6-
7-
</Application>
1+
<local:ExampleApp x:Class="Example.UWP.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="using:Example.UWP"
5+
RequestedTheme="Dark">
6+
<Application.Resources>
7+
<x:String x:Key="WelcomeText">Hello World!</x:String>
8+
</Application.Resources>
9+
</local:ExampleApp>
Lines changed: 27 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,42 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.IO;
4-
using System.Linq;
5-
using System.Runtime.InteropServices.WindowsRuntime;
2+
using MvvmCross;
3+
using MvvmCross.Platforms.Uap.Core;
4+
using MvvmCross.Platforms.Uap.Views;
65
using Windows.ApplicationModel;
76
using Windows.ApplicationModel.Activation;
8-
using Windows.Foundation;
9-
using Windows.Foundation.Collections;
7+
using Windows.UI.Popups;
108
using Windows.UI.Xaml;
119
using Windows.UI.Xaml.Controls;
12-
using Windows.UI.Xaml.Controls.Primitives;
13-
using Windows.UI.Xaml.Data;
14-
using Windows.UI.Xaml.Input;
15-
using Windows.UI.Xaml.Media;
1610
using Windows.UI.Xaml.Navigation;
1711

1812
namespace Example.UWP
1913
{
14+
public abstract class ExampleApp : MvxApplication<MvxWindowsSetup<CoreApp>, CoreApp>
15+
{
16+
}
17+
18+
/// <summary>
19+
/// Provides application-specific behavior to supplement the default Application class.
20+
/// </summary>
21+
public sealed partial class App
22+
{
2023
/// <summary>
21-
/// Provides application-specific behavior to supplement the default Application class.
24+
/// Initializes the singleton application object. This is the first line of authored code
25+
/// executed, and as such is the logical equivalent of main() or WinMain().
2226
/// </summary>
23-
sealed partial class App : Application
27+
public App()
2428
{
25-
/// <summary>
26-
/// Initializes the singleton application object. This is the first line of authored code
27-
/// executed, and as such is the logical equivalent of main() or WinMain().
28-
/// </summary>
29-
public App()
30-
{
31-
this.InitializeComponent();
32-
this.Suspending += OnSuspending;
33-
}
34-
35-
/// <summary>
36-
/// Invoked when the application is launched normally by the end user. Other entry points
37-
/// will be used such as when the application is launched to open a specific file.
38-
/// </summary>
39-
/// <param name="e">Details about the launch request and process.</param>
40-
protected override void OnLaunched(LaunchActivatedEventArgs e)
41-
{
42-
Frame rootFrame = Window.Current.Content as Frame;
43-
44-
// Do not repeat app initialization when the Window already has content,
45-
// just ensure that the window is active
46-
if (rootFrame == null)
47-
{
48-
// Create a Frame to act as the navigation context and navigate to the first page
49-
rootFrame = new Frame();
50-
51-
rootFrame.NavigationFailed += OnNavigationFailed;
52-
53-
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
54-
{
55-
//TODO: Load state from previously suspended application
56-
}
57-
58-
// Place the frame in the current Window
59-
Window.Current.Content = rootFrame;
60-
}
61-
62-
if (e.PrelaunchActivated == false)
63-
{
64-
if (rootFrame.Content == null)
65-
{
66-
// When the navigation stack isn't restored navigate to the first page,
67-
// configuring the new page by passing required information as a navigation
68-
// parameter
69-
rootFrame.Navigate(typeof(MainPage), e.Arguments);
70-
}
71-
// Ensure the current window is active
72-
Window.Current.Activate();
73-
}
74-
}
75-
76-
/// <summary>
77-
/// Invoked when Navigation to a certain page fails
78-
/// </summary>
79-
/// <param name="sender">The Frame which failed navigation</param>
80-
/// <param name="e">Details about the navigation failure</param>
81-
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
82-
{
83-
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
84-
}
29+
InitializeComponent();
30+
}
8531

86-
/// <summary>
87-
/// Invoked when application execution is being suspended. Application state is saved
88-
/// without knowing whether the application will be terminated or resumed with the contents
89-
/// of memory still intact.
90-
/// </summary>
91-
/// <param name="sender">The source of the suspend request.</param>
92-
/// <param name="e">Details about the suspend request.</param>
93-
private void OnSuspending(object sender, SuspendingEventArgs e)
94-
{
95-
var deferral = e.SuspendingOperation.GetDeferral();
96-
//TODO: Save application state and stop any background activity
97-
deferral.Complete();
98-
}
32+
protected override void OnActivated(IActivatedEventArgs args)
33+
{
34+
if (args.Kind == ActivationKind.Protocol)
35+
{
36+
ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;
37+
var publisher = Mvx.IoCProvider.Resolve<ITokenPublisherService>();
38+
publisher.ReceiveToken(eventArgs.Uri);
39+
}
9940
}
41+
}
10042
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Example.UWP.ViewModels;
2+
using MvvmCross.IoC;
3+
using MvvmCross.ViewModels;
4+
5+
namespace Example.UWP
6+
{
7+
public class CoreApp : MvxApplication
8+
{
9+
public override void Initialize()
10+
{
11+
CreatableTypes()
12+
.EndingWith("Service")
13+
.AsInterfaces()
14+
.RegisterAsLazySingleton();
15+
16+
RegisterAppStart<LoginViewModel>();
17+
}
18+
}
19+
}

‎SpotifyAPI.Web.Examples/Example.UWP/Example.UWP.csproj‎

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
<PropertyGroup>
55
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
66
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
7-
<ProjectGuid>{8968B88F-3A6B-4012-8449-B502C7CD658A}</ProjectGuid>
7+
<ProjectGuid>{70D529B5-CEC0-4D3D-B50D-8ECF921DEC70}</ProjectGuid>
88
<OutputType>AppContainerExe</OutputType>
99
<AppDesignerFolder>Properties</AppDesignerFolder>
10-
<RootNamespace>UWP</RootNamespace>
11-
<AssemblyName>UWP</AssemblyName>
10+
<RootNamespace>Example.UWP</RootNamespace>
11+
<AssemblyName>Example.UWP</AssemblyName>
1212
<DefaultLanguage>en-US</DefaultLanguage>
1313
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
1414
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.18362.0</TargetPlatformVersion>
@@ -119,10 +119,17 @@
119119
<Compile Include="App.xaml.cs">
120120
<DependentUpon>App.xaml</DependentUpon>
121121
</Compile>
122-
<Compile Include="MainPage.xaml.cs">
123-
<DependentUpon>MainPage.xaml</DependentUpon>
124-
</Compile>
122+
<Compile Include="CoreApp.cs" />
125123
<Compile Include="Properties\AssemblyInfo.cs" />
124+
<Compile Include="TokenPublisherService.cs" />
125+
<Compile Include="ViewModels\LoginViewModel.cs" />
126+
<Compile Include="ViewModels\PlaylistsListViewModel.cs" />
127+
<Compile Include="Views\LoginView.xaml.cs">
128+
<DependentUpon>LoginView.xaml</DependentUpon>
129+
</Compile>
130+
<Compile Include="Views\PlaylistsListView.xaml.cs">
131+
<DependentUpon>PlaylistsListView.xaml</DependentUpon>
132+
</Compile>
126133
</ItemGroup>
127134
<ItemGroup>
128135
<AppxManifest Include="Package.appxmanifest">
@@ -144,15 +151,30 @@
144151
<Generator>MSBuild:Compile</Generator>
145152
<SubType>Designer</SubType>
146153
</ApplicationDefinition>
147-
<Page Include="MainPage.xaml">
148-
<Generator>MSBuild:Compile</Generator>
149-
<SubType>Designer</SubType>
150-
</Page>
151154
</ItemGroup>
152155
<ItemGroup>
153156
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
154157
<Version>6.2.9</Version>
155158
</PackageReference>
159+
<PackageReference Include="MvvmCross">
160+
<Version>6.4.2</Version>
161+
</PackageReference>
162+
</ItemGroup>
163+
<ItemGroup>
164+
<Page Include="Views\LoginView.xaml">
165+
<SubType>Designer</SubType>
166+
<Generator>MSBuild:Compile</Generator>
167+
</Page>
168+
<Page Include="Views\PlaylistsListView.xaml">
169+
<SubType>Designer</SubType>
170+
<Generator>MSBuild:Compile</Generator>
171+
</Page>
172+
</ItemGroup>
173+
<ItemGroup>
174+
<ProjectReference Include="..\..\SpotifyAPI.Web\SpotifyAPI.Web.csproj">
175+
<Project>{ec8a93ba-27c4-4642-b7a0-11b809c35be4}</Project>
176+
<Name>SpotifyAPI.Web</Name>
177+
</ProjectReference>
156178
</ItemGroup>
157179
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
158180
<VisualStudioVersion>14.0</VisualStudioVersion>

‎SpotifyAPI.Web.Examples/Example.UWP/MainPage.xaml‎

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)