Skip to content

Commit 9ea68ae

Browse files
committed
Xamarin UWP client login working again (needs to add a new redirect URI for Identity Server in server side)
1 parent 5f60b5a commit 9ea68ae

7 files changed

Lines changed: 53 additions & 9 deletions

File tree

src/Mobile/eShopOnContainers/eShopOnContainers.Core/App.xaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@
106106
<converters:InverseBoolConverter x:Key="InverseBoolConverter" />
107107
<converters:ItemsToHeightConverter x:Key="ItemsToHeightConverter" />
108108
<converters:ToUpperConverter x:Key="ToUpperConverter" />
109-
<converters:WebNavigatingEventArgsConverter x:Key="WebNavigatingEventArgsConverter" />
110-
109+
<converters:WebNavigatingEventArgsConverter x:Key="WebNavigatingEventArgsConverter" />
110+
<converters:WebNavigatedEventArgsConverter x:Key="WebNavigatedEventArgsConverter" />
111+
111112
<!-- STYLES -->
112113
<Style x:Key="EntryStyle"
113114
TargetType="{x:Type Entry}">
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Globalization;
3+
using Xamarin.Forms;
4+
5+
namespace eShopOnContainers.Core.Converters
6+
{
7+
public class WebNavigatedEventArgsConverter : IValueConverter
8+
{
9+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
10+
{
11+
var eventArgs = value as WebNavigatedEventArgs;
12+
if (eventArgs == null)
13+
throw new ArgumentException("Expected WebNavigatedEventArgs as value", "value");
14+
15+
return eventArgs.Url;
16+
}
17+
18+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
19+
{
20+
throw new NotImplementedException();
21+
}
22+
}
23+
}

src/Mobile/eShopOnContainers/eShopOnContainers.Core/GlobalSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private void UpdateEndpoint(string baseEndpoint)
6060
IdentityEndpoint = string.Format("{0}:5105/connect/authorize", baseEndpoint);
6161
UserInfoEndpoint = string.Format("{0}:5105/connect/userinfo", baseEndpoint);
6262
LogoutEndpoint = string.Format("{0}:5105/connect/endsession", baseEndpoint);
63-
IdentityCallback = "http://eshopxamarin/callback.html";
63+
IdentityCallback = string.Format("{0}:5105/xamarincallback", baseEndpoint);
6464
LogoutCallback = string.Format("{0}:5105/Account/Redirecting", baseEndpoint);
6565
}
6666
}

src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/LoginViewModel.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,16 @@ private void Logout()
221221

222222
private async Task NavigateAsync(string url)
223223
{
224-
if (url.Equals(GlobalSetting.Instance.LogoutCallback))
224+
var unescapedUrl = System.Net.WebUtility.UrlDecode(url);
225+
226+
if (unescapedUrl.Equals(GlobalSetting.Instance.LogoutCallback))
225227
{
226228
Settings.AuthAccessToken = string.Empty;
227229
Settings.AuthIdToken = string.Empty;
228230
IsLogin = false;
229231
LoginUrl = _identityService.CreateAuthorizeRequest();
230232
}
231-
else if (url.Contains(GlobalSetting.Instance.IdentityCallback))
233+
else if (unescapedUrl.Contains(GlobalSetting.Instance.IdentityCallback))
232234
{
233235
var authResponse = new AuthorizeResponse(url);
234236

src/Mobile/eShopOnContainers/eShopOnContainers.Core/Views/LoginView.xaml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,26 @@
313313
AbsoluteLayout.LayoutBounds="0, 0, 1, 1"
314314
AbsoluteLayout.LayoutFlags="All">
315315
<WebView.Behaviors>
316-
<behaviors:EventToCommandBehavior
317-
EventName="Navigating"
318-
EventArgsConverter="{StaticResource WebNavigatingEventArgsConverter}"
319-
Command="{Binding NavigateCommand}" />
316+
<OnPlatform x:TypeArguments="Behavior">
317+
<OnPlatform.Android>
318+
<behaviors:EventToCommandBehavior
319+
EventName="Navigating"
320+
EventArgsConverter="{StaticResource WebNavigatingEventArgsConverter}"
321+
Command="{Binding NavigateCommand}" />
322+
</OnPlatform.Android>
323+
<OnPlatform.iOS>
324+
<behaviors:EventToCommandBehavior
325+
EventName="Navigating"
326+
EventArgsConverter="{StaticResource WebNavigatingEventArgsConverter}"
327+
Command="{Binding NavigateCommand}" />
328+
</OnPlatform.iOS>
329+
<OnPlatform.WinPhone>
330+
<behaviors:EventToCommandBehavior
331+
EventName="Navigated"
332+
EventArgsConverter="{StaticResource WebNavigatedEventArgsConverter}"
333+
Command="{Binding NavigateCommand}" />
334+
</OnPlatform.WinPhone>
335+
</OnPlatform>
320336
</WebView.Behaviors>
321337
</WebView>
322338
</AbsoluteLayout>

src/Mobile/eShopOnContainers/eShopOnContainers.Core/eShopOnContainers.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
<Compile Include="Converters\ItemsToHeightConverter.cs" />
5959
<Compile Include="Converters\ItemTappedEventArgsConverter.cs" />
6060
<Compile Include="Converters\ToUpperConverter.cs" />
61+
<Compile Include="Converters\WebNavigatedEventArgsConverter.cs" />
6162
<Compile Include="Effects\LineColorEffect.cs" />
6263
<Compile Include="Exceptions\ServiceAuthenticationException.cs" />
6364
<Compile Include="Extensions\AnimationExtension.cs" />

src/Mobile/eShopOnContainers/eShopOnContainers.Windows/Package.appxmanifest

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@
2424
</Applications>
2525
<Capabilities>
2626
<Capability Name="internetClient" />
27+
<Capability Name="privateNetworkClientServer" />
2728
</Capabilities>
2829
</Package>

0 commit comments

Comments
 (0)