AJAX:通过src加载视频的JWT身份验证 [英] AJAX: JWT auth for video load via src

查看:105
本文介绍了AJAX:通过src加载视频的JWT身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从需要JWT网络令牌的API请求视频:

I am requesting a video from an API that requires JWT web tokens:

    // when the ajax call is done (the tolken is recieved )
    getAccessToken.done(function(data) {


        var d = JSON.stringify({'fpath': fpath})
        // get the download url
        var downloadurl = $.ajax({
            type: "POST",
            url: "https://gcp.inbcu.com/download",
            beforeSend: function(xhr){
                xhr.setRequestHeader("Authorization", "JWT " +  data.access_token);
            },
            contentType: 'application/json',
            data: d,
            success: function(response){
                $('#video-source').attr('src', response.url)
                $('#myvideo').load()
            },
            error:function(jqXHR, textStatus, errorThrown) {
                console.log("request for download url failed: ", textStatus, errorThrown, jqXHR);
            },
            dataType: 'json'
        });

此ajax调用本身成功(200),并返回正确的值.主要是它返回一个URL来设置视频的来源.

This ajax call itself is successful (200) and returns the proper values. Mainly it returns a url to set the source of the video.

问题是,视频src尝试访问URL,并且没有权限(没有jwt令牌/授权).加载视频的src时,如何在获得适当许可的情况下加载视频?这可能吗?

Problem is, the video src attempts to access the url and doesn't have permission (no jwt token/ authorization). How am I supposed to load the video with the proper permission when loading the src of a video? Is this possible?

推荐答案

作为

As the answer to a similar question explains, this isn't possible. Either you need to do it as an AJAX request, which you previously did, but which was slow, or, you need to add additional methods for the server to accept authentication.

关于这些身份验证选项,您可以添加服务器可以检查的会话cookie,或将令牌附加到视频网址,例如response.url + '?token=' + token.

Regarding these auth options, you could add a session cookie that the server can check, or append the token to the video url, like response.url + '?token=' + token.

这篇关于AJAX:通过src加载视频的JWT身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆