Skip to content

Commit f808142

Browse files
authored
Merge pull request #43 from GetStream/core-31
2 parents 5344e46 + 4b52384 commit f808142

File tree

5 files changed

+35
-39
lines changed

5 files changed

+35
-39
lines changed

appveyor.yml

18 Bytes
Binary file not shown.

src/stream-net-tests/ClientTests.cs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
using NUnit.Framework;
1+
using Newtonsoft.Json;
2+
using NUnit.Framework;
23
using System;
34
using System.Collections.Generic;
45
using System.Linq;
56
using System.Text;
6-
using Microsoft.IdentityModel.Tokens.JWT;
77
using System.Threading.Tasks;
88

99
namespace stream_net_tests
@@ -111,30 +111,32 @@ public void TestActivityPartialUpdateArgumentValidation()
111111
[Test]
112112
public void TestToken()
113113
{
114-
var tokenString = _client.CreateUserToken("user");
115-
var tok = new JWTSecurityToken(tokenString);
116-
object actualUserID;
117-
Assert.True(tok.Payload.TryGetValue("user_id", out actualUserID));
118-
Assert.AreEqual("user", (string)actualUserID);
114+
var result = DecodeJWT(_client.CreateUserToken("user"));
115+
Assert.AreEqual("user", (string)result["user_id"]);
119116

120117
var extra = new Dictionary<string, object>()
121118
{
122119
{"client","dotnet"},
123120
{"testing", true}
124121
};
125-
tokenString = _client.CreateUserToken("user2", extra);
126-
tok = new JWTSecurityToken(tokenString);
122+
result = DecodeJWT(_client.CreateUserToken("user2", extra));
127123

128-
object data;
129-
130-
Assert.True(tok.Payload.TryGetValue("user_id", out data));
131-
Assert.AreEqual("user2", (string)data);
132-
Assert.True(tok.Payload.TryGetValue("client", out data));
133-
Assert.AreEqual("dotnet", (string)data);
134-
Assert.True(tok.Payload.TryGetValue("testing", out data));
135-
Assert.AreEqual(true, (bool)data);
124+
Assert.AreEqual("user2", (string)result["user_id"]);
125+
Assert.AreEqual("dotnet", (string)result["client"]);
126+
Assert.AreEqual(true, (bool)result["testing"]);
127+
Assert.False(result.ContainsKey("missing"));
128+
}
136129

137-
Assert.False(tok.Payload.ContainsKey("missing"));
130+
private Dictionary<string, object> DecodeJWT(string token)
131+
{
132+
var segment = token.Split('.')[1];
133+
var mod = segment.Length % 4;
134+
if (mod > 0) {
135+
segment += "".PadLeft(4-mod, '=');
136+
}
137+
var encoded = Convert.FromBase64String(segment.Replace('-', '+').Replace('_', '/'));
138+
var payload = Encoding.UTF8.GetString(encoded);
139+
return JsonConvert.DeserializeObject<Dictionary<string, object>>(payload);
138140
}
139141
}
140142
}

src/stream-net-tests/stream-net-tests.csproj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk">
1+
<Project ToolsVersion="16.5" Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup Label="Configuration">
33
<DefineConstants>TRACE;DEBUG;NETCORE</DefineConstants>
44
</PropertyGroup>
55
<PropertyGroup>
6-
<TargetFrameworks>net461</TargetFrameworks>
6+
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
77
<IsPackable>false</IsPackable>
88
</PropertyGroup>
99
<ItemGroup>
1010
<PackageReference Include="coveralls.io" Version="1.4.2" />
11-
<PackageReference Include="Microsoft.IdentityModel.Tokens.JWT" Version="0.1.0" />
12-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
1312
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
1413
<PackageReference Include="NUnit" Version="3.12.0" />
1514
<PackageReference Include="NUnit.Console" Version="3.10.0" />

src/stream-net/StreamClient.cs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class StreamClient : IStreamClient
1919
internal const string BasePersonalizationUrlPath = "/personalization/v1.0/";
2020
internal const string ActivitiesUrlPath = "activities/";
2121
internal const string ImagesUrlPath = "images/";
22-
22+
2323
internal const int ActivityCopyLimitDefault = 300;
2424
internal const int ActivityCopyLimitMax = 1000;
2525

@@ -78,11 +78,7 @@ public IStreamFeed Feed(string feedSlug, string userId)
7878
return new StreamFeed(this, feedSlug, userId);
7979
}
8080

81-
82-
83-
84-
85-
public async Task ActivityPartialUpdate(string id = null, ForeignIDTime foreignIDTime = null, GenericData set = null, IEnumerable<string> unset = null)
81+
public async Task ActivityPartialUpdate(string id = null, ForeignIDTime foreignIDTime = null, GenericData set = null, IEnumerable<string> unset = null)
8682
{
8783
if (id == null && foreignIDTime == null)
8884
throw new ArgumentException("one the parameters ids or foreignIdTimes must be provided and not null", "ids, foreignIDTimes");
@@ -148,16 +144,15 @@ public Personalization Personalization
148144
}
149145
}
150146

151-
public Images Images
152-
{
153-
get
154-
{
155-
return new Images(this);
156-
}
157-
}
158-
147+
public Images Images
148+
{
149+
get
150+
{
151+
return new Images(this);
152+
}
153+
}
159154

160-
private Uri GetBaseUrl(StreamApiLocation location)
155+
private Uri GetBaseUrl(StreamApiLocation location)
161156
{
162157
return new Uri(string.Format(BaseUrlFormat, GetRegion(_options.Location)));
163158
}

src/stream-net/stream-net.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk">
1+
<Project ToolsVersion="16.5" Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup Label="Configuration">
33
<DefineConstants>TRACE;DEBUG;NETCORE</DefineConstants>
44
</PropertyGroup>
55
<PropertyGroup>
6-
<TargetFrameworks>net45;net461;netcoreapp1.0;netcoreapp2.2;netstandard1.6;netstandard2.0</TargetFrameworks>
6+
<TargetFrameworks>net45;net461;netcoreapp1.0;netcoreapp2.2;netcoreapp3.1;netstandard1.6;netstandard2.0</TargetFrameworks>
77
</PropertyGroup>
88
<PropertyGroup>
99
<PackageId>stream-net</PackageId>

0 commit comments

Comments
 (0)