I have the following constellation:
- Client: Angular + ngx videogular (I can switch to azure media player)
- Server: .Net 6 + duende Identity Server for user authentication and authorization (Identity server 4)
Client app and the server are published in azure as static and service app.
The goal is to stream large videos (Videos on demand) with azure media service to certain authenticated and authorized users.
Example: User 1 can watch video A and B. User 2 can only watch video A.
I have set media service v3 as it as described in microsoft pages and I was able to stream assets from azure media service (e.g. as HLS source:
Client:
<video #videoElement #vgHls="vgHls" [vgHls]="hlsSource" [vgMedia]="$any(media)" #media [id]="videoId"
type="video/mp4" [autoplay]="false" preload="auto" crossorigin>
</video>
Server:
var configWrapper = new ConfigWrapper(configuration);
ServiceClientCredentials credentials;
credentials = await GetCredentialsInteractiveAuthAsync(configWrapper);
var client = new AzureMediaServicesClient(configWrapper.ArmEndpoint, credentials)
{
SubscriptionId = configWrapper.SubscriptionId,
};
var asset = await client.Assets.GetAsync(configWrapper.ResourceGroup, configWrapper.AccountName, "assetName");
var streamingLocators = await client.Assets.ListStreamingLocatorsAsync(configWrapper.ResourceGroup, configWrapper.AccountName, "assetName");
var locator = streamingLocators.StreamingLocators.FirstOrDefault();
IList<string> urls = await GetStreamingUrlsAsync(client, configWrapper.ResourceGroup, configWrapper.AccountName, locator.Name);
// return hlsUrl... It works for all users? (not only for authorized user?)
Now I don't want to enter the hls or dash sources in the client video player, but control the access rights in my api server.
How can I create an "hls source" for an azure asset in rest api only for an authenticated and authorized user?
How can I secure the videos/assets with tokens only for authorized users?