diff --git a/appveyor.yml b/appveyor.yml index bdb5c85..6aa709f 100644 Binary files a/appveyor.yml and b/appveyor.yml differ diff --git a/src/stream-net-tests/ClientTests.cs b/src/stream-net-tests/ClientTests.cs index 5993d53..a754909 100644 --- a/src/stream-net-tests/ClientTests.cs +++ b/src/stream-net-tests/ClientTests.cs @@ -1,9 +1,9 @@ -using NUnit.Framework; +using Newtonsoft.Json; +using NUnit.Framework; using System; using System.Collections.Generic; using System.Linq; using System.Text; -using Microsoft.IdentityModel.Tokens.JWT; using System.Threading.Tasks; namespace stream_net_tests @@ -111,30 +111,32 @@ public void TestActivityPartialUpdateArgumentValidation() [Test] public void TestToken() { - var tokenString = _client.CreateUserToken("user"); - var tok = new JWTSecurityToken(tokenString); - object actualUserID; - Assert.True(tok.Payload.TryGetValue("user_id", out actualUserID)); - Assert.AreEqual("user", (string)actualUserID); + var result = DecodeJWT(_client.CreateUserToken("user")); + Assert.AreEqual("user", (string)result["user_id"]); var extra = new Dictionary() { {"client","dotnet"}, {"testing", true} }; - tokenString = _client.CreateUserToken("user2", extra); - tok = new JWTSecurityToken(tokenString); + result = DecodeJWT(_client.CreateUserToken("user2", extra)); - object data; - - Assert.True(tok.Payload.TryGetValue("user_id", out data)); - Assert.AreEqual("user2", (string)data); - Assert.True(tok.Payload.TryGetValue("client", out data)); - Assert.AreEqual("dotnet", (string)data); - Assert.True(tok.Payload.TryGetValue("testing", out data)); - Assert.AreEqual(true, (bool)data); + Assert.AreEqual("user2", (string)result["user_id"]); + Assert.AreEqual("dotnet", (string)result["client"]); + Assert.AreEqual(true, (bool)result["testing"]); + Assert.False(result.ContainsKey("missing")); + } - Assert.False(tok.Payload.ContainsKey("missing")); + private Dictionary DecodeJWT(string token) + { + var segment = token.Split('.')[1]; + var mod = segment.Length % 4; + if (mod > 0) { + segment += "".PadLeft(4-mod, '='); + } + var encoded = Convert.FromBase64String(segment.Replace('-', '+').Replace('_', '/')); + var payload = Encoding.UTF8.GetString(encoded); + return JsonConvert.DeserializeObject>(payload); } } } diff --git a/src/stream-net-tests/stream-net-tests.csproj b/src/stream-net-tests/stream-net-tests.csproj index da34cd3..0f294bf 100644 --- a/src/stream-net-tests/stream-net-tests.csproj +++ b/src/stream-net-tests/stream-net-tests.csproj @@ -1,15 +1,14 @@ - + TRACE;DEBUG;NETCORE - net461 + netcoreapp3.1 false - - + diff --git a/src/stream-net/StreamClient.cs b/src/stream-net/StreamClient.cs index 15c704e..f64726f 100644 --- a/src/stream-net/StreamClient.cs +++ b/src/stream-net/StreamClient.cs @@ -19,7 +19,7 @@ public class StreamClient : IStreamClient internal const string BasePersonalizationUrlPath = "/personalization/v1.0/"; internal const string ActivitiesUrlPath = "activities/"; internal const string ImagesUrlPath = "images/"; - + internal const int ActivityCopyLimitDefault = 300; internal const int ActivityCopyLimitMax = 1000; @@ -78,11 +78,7 @@ public IStreamFeed Feed(string feedSlug, string userId) return new StreamFeed(this, feedSlug, userId); } - - - - - public async Task ActivityPartialUpdate(string id = null, ForeignIDTime foreignIDTime = null, GenericData set = null, IEnumerable unset = null) + public async Task ActivityPartialUpdate(string id = null, ForeignIDTime foreignIDTime = null, GenericData set = null, IEnumerable unset = null) { if (id == null && foreignIDTime == null) throw new ArgumentException("one the parameters ids or foreignIdTimes must be provided and not null", "ids, foreignIDTimes"); @@ -148,16 +144,15 @@ public Personalization Personalization } } - public Images Images - { - get - { - return new Images(this); - } - } - + public Images Images + { + get + { + return new Images(this); + } + } - private Uri GetBaseUrl(StreamApiLocation location) + private Uri GetBaseUrl(StreamApiLocation location) { return new Uri(string.Format(BaseUrlFormat, GetRegion(_options.Location))); } diff --git a/src/stream-net/stream-net.csproj b/src/stream-net/stream-net.csproj index 0fed872..9dd3d85 100644 --- a/src/stream-net/stream-net.csproj +++ b/src/stream-net/stream-net.csproj @@ -1,9 +1,9 @@ - + TRACE;DEBUG;NETCORE - net45;net461;netcoreapp1.0;netcoreapp2.2;netstandard1.6;netstandard2.0 + net45;net461;netcoreapp1.0;netcoreapp2.2;netcoreapp3.1;netstandard1.6;netstandard2.0 stream-net