VideoUIKit-Flutter icon indicating copy to clipboard operation
VideoUIKit-Flutter copied to clipboard

Accept getToken callback in AgoraConnectionData

Open iamriajul opened this issue 2 years ago • 5 comments

Is your feature request related to a problem? Please describe. I've my agora-token-service deployed but is not exposed as a public API, What we do is we have our API endpoint which verifies authentication and type of user the currently authenticated, and other business logic and then based on that data we generate a token using the agora-token-service, and also we deny with error message in-case the authenticated user doesn't satisfy business logic or don't have access to that channel.

Describe the solution you'd like I want to be able to pass a parameter something like this:

final connectionDataProvider = FutureProvider.autoDispose((ref) {
   // The API has middleware, which attaches things like Authorization Bearer Token, to authenticate current user.
   final api = ref.watch(apiProvider);
   final callInfo = ref.watch(callInfoProvider);
   return AgoraConnectionData(
    appId: "<APP_ID>",
    channelName: callInfo.roomId,
    uid: callInfo.userId,
    getToken: () async => (await api.getVideoCallToken(callInfo.roomId)).token,
  );
}); 

Describe alternatives you've considered Currently thinking to pass my token using tempToken parameter, but I'm not sure about this solution. As I've seen Temp Token generated from the Agora dashboard has a longer expiry time (around 1 day). but my token generated from my API Endpoint has only 5 minutes of expiry time.

Additional context I'm using Agora UIKit Flutter: 1.3.6 agora-token-service: 1.4.2 ( using this Docker Image: https://hub.docker.com/r/iamriajul/agora-token-service )

Thanks.

iamriajul avatar Aug 18 '23 09:08 iamriajul

passing a closure would be a really nice option! the only awkward thing is it would then have three separate options; token url, temp token, and a “get token” callback.

this could be done with ios/swift using an enum with an associated types:

enum TokenType {
    case tempToken(String)
    case tokenUrl(String)
    case getToken((channel: String) -> String?)
}

obj.token = .getToken({…})
// or .tempToken(“abcde”)

is something similar possible in Dart?

maxxfrazer avatar Aug 18 '23 20:08 maxxfrazer

is something similar possible in Dart?

I don't think dart support that.

iamriajul avatar Aug 19 '23 04:08 iamriajul

And changing the existing API for ConnectionData would cause an issue.

I've seen that the SDK uses the tokenUrl to generate tokens for both RTC & RTM (if enabled).

To support both scenarios we might need to add two separate callback parameters.

  • getRtcToken(String channel, int uid) nullable
  • getRtmToken(String channel, int uid) nullable

Another thing I've noticed is that the SDK is using the deprecated routes for agora-token-service, The SDK should be using the POST /getToken endpoint for generating both types of token, which I think should be resolved first.

iamriajul avatar Aug 19 '23 04:08 iamriajul

Another thing I've noticed is that the SDK is using the deprecated routes for agora-token-service, The SDK should be using the POST /getToken endpoint for generating both types of token, which I think should be resolved first.

If you want I can make a PR on this issue.

iamriajul avatar Aug 19 '23 04:08 iamriajul

damn @iamriajul, you're pretty quick - I only added the /getToken endpoint earlier this month 😅 feel free to make a PR if you get chance. all the projects will eventually migrate so that's be great to kick off with this one!

maxxfrazer avatar Aug 21 '23 08:08 maxxfrazer