Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified appveyor.yml
Binary file not shown.
38 changes: 20 additions & 18 deletions src/stream-net-tests/ClientTests.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<string, object>()
{
{"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<string, object> 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<Dictionary<string, object>>(payload);
}
}
}
7 changes: 3 additions & 4 deletions src/stream-net-tests/stream-net-tests.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk">
<Project ToolsVersion="16.5" Sdk="Microsoft.NET.Sdk">
<PropertyGroup Label="Configuration">
<DefineConstants>TRACE;DEBUG;NETCORE</DefineConstants>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>net461</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coveralls.io" Version="1.4.2" />
<PackageReference Include="Microsoft.IdentityModel.Tokens.JWT" Version="0.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit.Console" Version="3.10.0" />
Expand Down
25 changes: 10 additions & 15 deletions src/stream-net/StreamClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<string> unset = null)
public async Task ActivityPartialUpdate(string id = null, ForeignIDTime foreignIDTime = null, GenericData set = null, IEnumerable<string> unset = null)
{
if (id == null && foreignIDTime == null)
throw new ArgumentException("one the parameters ids or foreignIdTimes must be provided and not null", "ids, foreignIDTimes");
Expand Down Expand Up @@ -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)));
}
Expand Down
4 changes: 2 additions & 2 deletions src/stream-net/stream-net.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk">
<Project ToolsVersion="16.5" Sdk="Microsoft.NET.Sdk">
<PropertyGroup Label="Configuration">
<DefineConstants>TRACE;DEBUG;NETCORE</DefineConstants>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>net45;net461;netcoreapp1.0;netcoreapp2.2;netstandard1.6;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net45;net461;netcoreapp1.0;netcoreapp2.2;netcoreapp3.1;netstandard1.6;netstandard2.0</TargetFrameworks>
</PropertyGroup>
<PropertyGroup>
<PackageId>stream-net</PackageId>
Expand Down