Skip to content

Commit bf7ed3f

Browse files
committed
2 parents d3413dd + b285eef commit bf7ed3f

18 files changed

Lines changed: 162 additions & 14 deletions

File tree

3.58 KB
Binary file not shown.

eShopOnContainers-MobileApps.sln

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26228.9
4+
VisualStudioVersion = 15.0.26430.16
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{932D8224-11F6-4D07-B109-DA28AD288A63}"
77
EndProject
@@ -473,6 +473,8 @@ Global
473473
{A7337243-33B8-463A-87AD-944B75EFD820}.AppStore|x86.Build.0 = Release|x86
474474
{A7337243-33B8-463A-87AD-944B75EFD820}.AppStore|x86.Deploy.0 = Release|x86
475475
{A7337243-33B8-463A-87AD-944B75EFD820}.Debug|Any CPU.ActiveCfg = Debug|x86
476+
{A7337243-33B8-463A-87AD-944B75EFD820}.Debug|Any CPU.Build.0 = Debug|x86
477+
{A7337243-33B8-463A-87AD-944B75EFD820}.Debug|Any CPU.Deploy.0 = Debug|x86
476478
{A7337243-33B8-463A-87AD-944B75EFD820}.Debug|ARM.ActiveCfg = Debug|ARM
477479
{A7337243-33B8-463A-87AD-944B75EFD820}.Debug|ARM.Build.0 = Debug|ARM
478480
{A7337243-33B8-463A-87AD-944B75EFD820}.Debug|ARM.Deploy.0 = Debug|ARM
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.Text;
2+
3+
namespace eShopOnContainers.Core.Helpers
4+
{
5+
internal static class RandomNumberGenerator
6+
{
7+
public static string CreateUniqueId(int length = 64)
8+
{
9+
var bytes = PCLCrypto.WinRTCrypto.CryptographicBuffer.GenerateRandom(length);
10+
return ByteArrayToString(bytes);
11+
}
12+
13+
private static string ByteArrayToString(byte[] array)
14+
{
15+
var hex = new StringBuilder(array.Length * 2);
16+
foreach (byte b in array)
17+
{
18+
hex.AppendFormat("{0:x2}", b);
19+
}
20+
return hex.ToString();
21+
}
22+
}
23+
}

src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Identity/IdentityService.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
using IdentityModel.Client;
2-
using System;
1+
using System;
32
using System.Collections.Generic;
43
using System.Net;
4+
using System.Text;
55
using System.Threading.Tasks;
66
using eShopOnContainers.Core.Services.RequestProvider;
77
using eShopOnContainers.Core.Models.Token;
8+
using eShopOnContainers.Core.Helpers;
9+
using IdentityModel;
10+
using IdentityModel.Client;
11+
using PCLCrypto;
12+
using static PCLCrypto.WinRTCrypto;
813

914
namespace eShopOnContainers.Core.Services.Identity
1015
{
1116
public class IdentityService : IIdentityService
1217
{
1318
private readonly IRequestProvider _requestProvider;
19+
private string _codeVerifier;
1420

1521
public IdentityService(IRequestProvider requestProvider)
1622
{
@@ -30,6 +36,8 @@ public string CreateAuthorizationRequest()
3036
dic.Add("scope", "openid profile basket orders locations marketing offline_access");
3137
dic.Add("redirect_uri", GlobalSetting.Instance.IdentityCallback);
3238
dic.Add("nonce", Guid.NewGuid().ToString("N"));
39+
dic.Add("code_challenge", CreateCodeChallenge());
40+
dic.Add("code_challenge_method", "S256");
3341

3442
// Add CSRF token to protect against cross-site request forgery attacks.
3543
var currentCSRFToken = Guid.NewGuid().ToString("N");
@@ -54,9 +62,19 @@ public string CreateLogoutRequest(string token)
5462

5563
public async Task<UserToken> GetTokenAsync(string code)
5664
{
57-
string data = string.Format("grant_type=authorization_code&code={0}&redirect_uri={1}", code, WebUtility.UrlEncode(GlobalSetting.Instance.IdentityCallback));
65+
string data = string.Format("grant_type=authorization_code&code={0}&redirect_uri={1}&code_verifier={2}", code, WebUtility.UrlEncode(GlobalSetting.Instance.IdentityCallback), _codeVerifier);
5866
var token = await _requestProvider.PostAsync<UserToken>(GlobalSetting.Instance.TokenEndpoint, data, GlobalSetting.Instance.ClientId, GlobalSetting.Instance.ClientSecret);
5967
return token;
6068
}
69+
70+
private string CreateCodeChallenge()
71+
{
72+
_codeVerifier = RandomNumberGenerator.CreateUniqueId();
73+
var sha256 = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithm.Sha256);
74+
var challengeBuffer = sha256.HashData(CryptographicBuffer.CreateFromByteArray(Encoding.UTF8.GetBytes(_codeVerifier)));
75+
byte[] challengeBytes;
76+
CryptographicBuffer.CopyToByteArray(challengeBuffer, out challengeBytes);
77+
return Base64Url.Encode(challengeBytes);
78+
}
6179
}
6280
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,27 +281,27 @@ private void UpdateInfoFakeLocation()
281281
if (!UseFakeLocation)
282282
{
283283
TitleUseFakeLocation = "Use Real Location";
284-
DescriptionUseFakeLocation = "When enabling the use of real location, the app will attempt to use real location from the device.";
284+
DescriptionUseFakeLocation = "When enabling location, the app will attempt to use the location from the device.";
285285

286286
}
287287
else
288288
{
289289
TitleUseFakeLocation = "Use Fake Location";
290-
DescriptionUseFakeLocation = "Fake Location are added for marketing campaign testing.";
290+
DescriptionUseFakeLocation = "Fake Location data is added for marketing campaign testing.";
291291
}
292292
}
293293

294294
private void UpdateInfoAllowGpsLocation()
295295
{
296296
if (!AllowGpsLocation)
297297
{
298-
TitleAllowGpsLocation = "GPS location Denied";
299-
DescriptionAllowGpsLocation = "When denying the use of device gps you won't get the location campaigns through your real location.";
298+
TitleAllowGpsLocation = "GPS Location Disabled";
299+
DescriptionAllowGpsLocation = "When disabling location, you won't receive location campaigns based upon your location.";
300300
}
301301
else
302302
{
303-
TitleAllowGpsLocation = "GPS location Allowed";
304-
DescriptionAllowGpsLocation = "When allowing the use of device gps you will get the location campaigns through your real location.";
303+
TitleAllowGpsLocation = "GPS Location Enabled";
304+
DescriptionAllowGpsLocation = "When enabling location, you'll receive location campaigns based upon your location.";
305305

306306
}
307307
}
@@ -344,7 +344,7 @@ private void UpdateAllowGpsLocation()
344344
if (!locator.IsGeolocationEnabled)
345345
{
346346
_allowGpsLocation = false;
347-
GpsWarningMessage = "Enable your GPS system in your device";
347+
GpsWarningMessage = "Enable the GPS sensor on your device";
348348
}
349349
else
350350
{

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
<Compile Include="Extensions\ObservableExtension.cs" />
6565
<Compile Include="GlobalSettings.cs" />
6666
<Compile Include="Helpers\EasingHelper.cs" />
67+
<Compile Include="Helpers\RandomNumberGenerator.cs" />
6768
<Compile Include="Helpers\ServicesHelper.cs" />
6869
<Compile Include="Helpers\Settings.cs" />
6970
<Compile Include="Models\Basket\BasketCheckout.cs" />

src/Mobile/eShopOnContainers/eShopOnContainers.Core/project.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"Microsoft.Net.Http": "2.2.29",
99
"modernhttpclient": "2.4.2",
1010
"Newtonsoft.Json": "9.0.1",
11+
"PCLCrypto": "2.0.147",
1112
"SlideOverKit": "2.1.4",
1213
"Splat": "1.6.2",
1314
"System.ComponentModel.Annotations": "4.3.0",

src/Mobile/eShopOnContainers/eShopOnContainers.Droid/eShopOnContainers.Droid.csproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,21 @@
100100
<HintPath>..\..\..\..\packages\modernhttpclient.2.4.2\lib\MonoAndroid\OkHttp.dll</HintPath>
101101
<Private>True</Private>
102102
</Reference>
103+
<Reference Include="PCLCrypto, Version=2.0.0.0, Culture=neutral, PublicKeyToken=d4421c8a4786956c, processorArchitecture=MSIL">
104+
<HintPath>..\..\..\..\packages\PCLCrypto.2.0.147\lib\MonoAndroid23\PCLCrypto.dll</HintPath>
105+
</Reference>
106+
<Reference Include="PInvoke.BCrypt, Version=0.3.0.0, Culture=neutral, PublicKeyToken=9e300f9f87f04a7a, processorArchitecture=MSIL">
107+
<HintPath>..\..\..\..\packages\PInvoke.BCrypt.0.3.2\lib\portable-net45+win+wpa81+MonoAndroid10+xamarinios10+MonoTouch10\PInvoke.BCrypt.dll</HintPath>
108+
</Reference>
109+
<Reference Include="PInvoke.Kernel32, Version=0.3.0.0, Culture=neutral, PublicKeyToken=9e300f9f87f04a7a, processorArchitecture=MSIL">
110+
<HintPath>..\..\..\..\packages\PInvoke.Kernel32.0.3.2\lib\portable-net45+win+wpa81+MonoAndroid10+xamarinios10+MonoTouch10\PInvoke.Kernel32.dll</HintPath>
111+
</Reference>
112+
<Reference Include="PInvoke.NCrypt, Version=0.3.0.0, Culture=neutral, PublicKeyToken=9e300f9f87f04a7a, processorArchitecture=MSIL">
113+
<HintPath>..\..\..\..\packages\PInvoke.NCrypt.0.3.2\lib\portable-net45+win+wpa81+MonoAndroid10+xamarinios10+MonoTouch10\PInvoke.NCrypt.dll</HintPath>
114+
</Reference>
115+
<Reference Include="PInvoke.Windows.Core, Version=0.3.0.0, Culture=neutral, PublicKeyToken=9e300f9f87f04a7a, processorArchitecture=MSIL">
116+
<HintPath>..\..\..\..\packages\PInvoke.Windows.Core.0.3.2\lib\portable-net45+win+wpa81+MonoAndroid10+xamarinios10+MonoTouch10\PInvoke.Windows.Core.dll</HintPath>
117+
</Reference>
103118
<Reference Include="Plugin.CurrentActivity, Version=1.0.1.0, Culture=neutral, processorArchitecture=MSIL">
104119
<HintPath>..\..\..\..\packages\Plugin.CurrentActivity.1.0.1\lib\MonoAndroid10\Plugin.CurrentActivity.dll</HintPath>
105120
</Reference>
@@ -149,6 +164,9 @@
149164
<Reference Include="System.ObjectModel" />
150165
<Reference Include="System.Xml.Linq" />
151166
<Reference Include="System.Xml" />
167+
<Reference Include="Validation, Version=2.2.0.0, Culture=neutral, PublicKeyToken=2fc06f0d701809a7, processorArchitecture=MSIL">
168+
<HintPath>..\..\..\..\packages\Validation.2.2.8\lib\dotnet\Validation.dll</HintPath>
169+
</Reference>
152170
<Reference Include="Xamarin.Android.Support.Animated.Vector.Drawable, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
153171
<HintPath>..\..\..\..\packages\Xamarin.Android.Support.Animated.Vector.Drawable.23.3.0\lib\MonoAndroid403\Xamarin.Android.Support.Animated.Vector.Drawable.dll</HintPath>
154172
<Private>True</Private>

src/Mobile/eShopOnContainers/eShopOnContainers.Droid/packages.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
<package id="modernhttpclient" version="2.4.2" targetFramework="monoandroid70" />
1515
<package id="NETStandard.Library" version="1.6.0" targetFramework="monoandroid60" />
1616
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="monoandroid60" />
17+
<package id="PCLCrypto" version="2.0.147" targetFramework="monoandroid60" />
18+
<package id="PInvoke.BCrypt" version="0.3.2" targetFramework="monoandroid60" />
19+
<package id="PInvoke.Kernel32" version="0.3.2" targetFramework="monoandroid60" />
20+
<package id="PInvoke.NCrypt" version="0.3.2" targetFramework="monoandroid60" />
21+
<package id="PInvoke.Windows.Core" version="0.3.2" targetFramework="monoandroid60" />
1722
<package id="Plugin.CurrentActivity" version="1.0.1" targetFramework="monoandroid60" />
1823
<package id="Plugin.Permissions" version="1.1.7" targetFramework="monoandroid60" />
1924
<package id="SlideOverKit" version="2.1.4" targetFramework="monoandroid70" />
@@ -63,6 +68,7 @@
6368
<package id="System.Threading.Timer" version="4.0.1" targetFramework="monoandroid60" />
6469
<package id="System.Xml.ReaderWriter" version="4.0.11" targetFramework="monoandroid70" />
6570
<package id="System.Xml.XDocument" version="4.0.11" targetFramework="monoandroid70" />
71+
<package id="Validation" version="2.2.8" targetFramework="monoandroid60" />
6672
<package id="Xam.Plugin.Geolocator" version="3.0.4" targetFramework="monoandroid60" />
6773
<package id="Xam.Plugins.Settings" version="2.6.0.12-beta" targetFramework="monoandroid70" />
6874
<package id="Xamarin.Android.Support.Animated.Vector.Drawable" version="23.3.0" targetFramework="monoandroid70" />

src/Mobile/eShopOnContainers/eShopOnContainers.TestRunner.Droid/Resources/Resource.Designer.cs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)