Skip to content

Commit

Permalink
fix: reuse T1 token until JWT expiration issue is fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d committed Dec 17, 2024
1 parent 7b2b297 commit cbd7690
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
1 change: 1 addition & 0 deletions OpenTok/OpenTok.cs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ public async Task<Session> CreateSessionAsync(string location = "", MediaMode me
/// <returns></returns>
public string GenerateToken(string sessionId, Role role = Role.PUBLISHER, double expireTime = 0, string data = null, List<string> initialLayoutClassList = null)
{
return this.GenerateT1Token(sessionId, role, expireTime, data, initialLayoutClassList);
if (String.IsNullOrEmpty(sessionId))

Check warning on line 408 in OpenTok/OpenTok.cs

View workflow job for this annotation

GitHub Actions / build

Unreachable code detected
{
throw new OpenTokArgumentException("Session id cannot be empty or null");
Expand Down
21 changes: 11 additions & 10 deletions OpenTok/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,17 @@ public string GenerateT1Token(Role role = Role.PUBLISHER, double expireTime = 0,
public string GenerateToken(Role role = Role.PUBLISHER, double expireTime = 0, string data = null, List<string> initialLayoutClassList = null) =>
!string.IsNullOrEmpty(this.ApplicationId)
? new TokenGenerator().GenerateSessionToken(this.ApplicationId, this.PrivateKey, this.Id)
: new TokenGenerator().GenerateSessionToken(new TokenData()
{
ApiSecret = this.ApiSecret,
Role = role,
ApiKey = this.ApiKey.ToString(),
Data = data,
SessionId = this.Id,
ExpireTime = expireTime,
InitialLayoutClasses = initialLayoutClassList ?? Enumerable.Empty<string>(),
});
: this.GenerateT1Token(role, expireTime, data, initialLayoutClassList);
// : new TokenGenerator().GenerateSessionToken(new TokenData()
// {
// ApiSecret = this.ApiSecret,
// Role = role,
// ApiKey = this.ApiKey.ToString(),
// Data = data,
// SessionId = this.Id,
// ExpireTime = expireTime,
// InitialLayoutClasses = initialLayoutClassList ?? Enumerable.Empty<string>(),
// });

private string BuildTokenString(string dataString)
{
Expand Down
10 changes: 5 additions & 5 deletions OpenTokTest/TokenTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public class TokenTests
private const string SessionId = "1_MX4xMjM0NTZ-flNhdCBNYXIgMTUgMTQ6NDI6MjMgUERUIDIwMTR-MC40OTAxMzAyNX4";
private readonly OpenTok sut = new(ApiKey, ApiSecret);

[Fact]
[Fact(Skip = "Until GA.")]
public void GenerateToken_ShouldReturnTokenWithDefaultValues()
{
var token = sut.GenerateToken(SessionId);
Expand All @@ -151,14 +151,14 @@ public void GenerateToken_ShouldReturnTokenWithDefaultValues()
claims.ContainsKey("initial_layout_class_list").Should().BeFalse();
}

[Fact]
[Fact(Skip = "Until GA.")]
public void GenerateToken_ShouldSetData()
{
var token = sut.GenerateToken(SessionId, data: "Some data.");
ExtractClaims(token)["connection_data"].Should().Be("Some data.");
}

[Fact]
[Fact(Skip = "Until GA.")]
public void GenerateToken_ShouldSetExpireTime()
{
var expireTime = new DateTimeOffset(DateTime.UtcNow.AddSeconds(30)).ToUnixTimeSeconds();
Expand All @@ -167,7 +167,7 @@ public void GenerateToken_ShouldSetExpireTime()
claims["exp"].Should().Be(expireTime.ToString(CultureInfo.InvariantCulture));
}

[Fact]
[Fact(Skip = "Until GA.")]
public void GenerateToken_ShouldSetInitialLayoutClass()
{
var list = new List<string> {"focus", "hello"};
Expand All @@ -176,7 +176,7 @@ public void GenerateToken_ShouldSetInitialLayoutClass()
claims["initial_layout_list"].Should().Be("focus hello");
}

[Theory]
[Theory(Skip = "Until GA.")]
[InlineData(Role.SUBSCRIBER, "subscriber")]
[InlineData(Role.PUBLISHER, "publisher")]
[InlineData(Role.MODERATOR, "moderator")]
Expand Down

0 comments on commit cbd7690

Please sign in to comment.