Skip to content

Commit 05af870

Browse files
authored
Merge pull request #146 from GetStream/feature/uni-107-enable-developer-tokens
Expose API for generating developer tokens + add unit test
2 parents 4196def + f279085 commit 05af870

File tree

8 files changed

+63
-2
lines changed

8 files changed

+63
-2
lines changed

Assets/Samples/Stream Video & Audio Chat SDK/0.8.1/Video & Audio Chat Example Project/Scripts/StreamVideoManager.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
using System.Net.Http;
34
using System.Threading.Tasks;
45
using StreamVideo.Core;
@@ -9,6 +10,9 @@
910
using StreamVideo.Libs.Serialization;
1011
using StreamVideo.Libs.Utils;
1112
using UnityEngine;
13+
#if STREAM_DEBUG_ENABLED
14+
using System.Linq;
15+
#endif
1216

1317
namespace StreamVideo.ExampleProject
1418
{

Packages/StreamVideo/Runtime/Core/LowLevelClient/StreamVideoLowLevelClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ var sfuWebSocket
8383
serializer, timeService, networkMonitor, applicationInfo, logs, config);
8484
}
8585

86-
//StreamTodo: review if this is valid for video SDK
86+
//StreamTodo: add video SDK docs link
8787
/// <summary>
8888
/// Create Development Authorization Token. Dev tokens work only if you enable "Disable Auth Checks" in your project's Dashboard.
8989
/// Dev tokens bypasses authorization and should only be used during development and never in production!

Packages/StreamVideo/Runtime/Core/StreamVideoClient.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
using StreamVideo.Core.State;
1818
using StreamVideo.Core.State.Caches;
1919
using StreamVideo.Core.StatefulModels;
20-
using StreamVideo.Core.Utils;
2120
using StreamVideo.Libs;
2221
using StreamVideo.Libs.AppInfo;
2322
using StreamVideo.Libs.Auth;
@@ -83,6 +82,13 @@ var sfuWebSocket
8382

8483
return client;
8584
}
85+
86+
/// <inheritdoc cref="StreamVideoLowLevelClient.CreateDeveloperAuthToken"/>
87+
public static string CreateDeveloperAuthToken(string userId)
88+
=> StreamVideoLowLevelClient.CreateDeveloperAuthToken(userId);
89+
90+
/// <inheritdoc cref="StreamVideoLowLevelClient.SanitizeUserId"/>
91+
public static string SanitizeUserId(string userId) => StreamVideoLowLevelClient.SanitizeUserId(userId);
8692

8793
//StreamTODO: this throws exception if the call doesn't exist. Check with other SDKs what is the expected behavior
8894
/// <summary>

Packages/StreamVideo/Samples~/VideoChat/Scripts/StreamVideoManager.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
using System.Net.Http;
34
using System.Threading.Tasks;
45
using StreamVideo.Core;
@@ -9,6 +10,9 @@
910
using StreamVideo.Libs.Serialization;
1011
using StreamVideo.Libs.Utils;
1112
using UnityEngine;
13+
#if STREAM_DEBUG_ENABLED
14+
using System.Linq;
15+
#endif
1216

1317
namespace StreamVideo.ExampleProject
1418
{
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#if STREAM_TESTS_ENABLED
2+
using System.Collections;
3+
using System.Threading.Tasks;
4+
using StreamVideo.Core;
5+
using StreamVideo.Libs.Auth;
6+
using StreamVideo.Tests.Shared;
7+
using UnityEngine.TestTools;
8+
9+
namespace StreamVideo.Tests.Runtime
10+
{
11+
internal class ConnectionTests : TestsBase
12+
{
13+
// StreamTODO: figure out passing specific api key to this test (with enabled "disable auth checks" flag)
14+
//[UnityTest]
15+
public IEnumerator When_connecting_developer_app_with_app_tokens_expect_no_issues()
16+
{
17+
yield return Execute(When_connecting_developer_app_with_app_tokens_expect_no_issues_Async);
18+
}
19+
20+
private async Task When_connecting_developer_app_with_app_tokens_expect_no_issues_Async()
21+
{
22+
// Only API KEY with "Disable Auth Checks" flag enabled will work here
23+
const string apiKey = "API_KEY";
24+
25+
var userName = "The Amazing Tom";
26+
var userId = StreamVideoClient.SanitizeUserId(userName);
27+
var userToken = StreamVideoClient.CreateDeveloperAuthToken(userId);
28+
var credentials = new AuthCredentials(apiKey, userId, userToken);
29+
30+
var client = StreamVideoClient.CreateDefaultClient();
31+
32+
var localUserData = await client.ConnectUserAsync(credentials);
33+
}
34+
}
35+
}
36+
#endif

Packages/StreamVideo/Tests/Runtime/ConnectionTests.cs.meta

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

Packages/StreamVideo/Tests/Shared/TestUtils.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public static IEnumerator RunAsIEnumerator(this Task task,
2424

2525
while (!task.IsCompleted)
2626
{
27+
//StreamTODO: implement timeout
2728
yield return null;
2829
}
2930

Packages/StreamVideo/Tests/Shared/TestsBase.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
namespace StreamVideo.Tests.Shared
1616
{
17+
public delegate Task NoClientTestHandler();
18+
1719
public delegate Task SingleClientTestHandler(ITestClient client);
1820

1921
public delegate Task TwoClientsTestHandler(ITestClient client1, ITestClient client2);
@@ -98,6 +100,11 @@ protected static IEnumerator ConnectAndExecute(TwoClientsTestHandler test, bool
98100
.RunAsIEnumerator(ignoreFailingMessages: ignoreFailingMessages);
99101
}
100102

103+
protected static IEnumerator Execute(NoClientTestHandler test)
104+
{
105+
yield return test().RunAsIEnumerator();
106+
}
107+
101108
private static bool IgnoreConditionKeyNoCameraDeviceIsSet;
102109

103110
private static async Task ConnectAndExecuteAsync(Func<ITestClient[], Task> test, int clientsToSpawn = 1)

0 commit comments

Comments
 (0)