Django rest_social_auth登录。如何处理facebook令牌?(Django rest_social_auth log in. What to do with facebook token?)
我正在使用django-rest-social-auth软件包允许用户在我的Django rest应用程序中进行身份验证。 我能够从Facebook为用户检索令牌。 现在,我不知道如何使用该令牌。 我正在尝试访问需要登录用户的端点,但我在调试时仅将访问视为匿名用户。 我一直在谷歌这个问题并尝试了很多不同的方法(不同的cookie,url params等)。
这是我的特例:
views.py
@login_required def home(request): return render(request, 'home.html')
我获得了我的令牌调用http:// localhost:8000 / api / login / social / token / (我正在关注django-rest-social-auth自述文件),它看起来像:
{"token": "4571b2dce1f3abec34b28a4c7bd981c248a30698"}
我有与我的用户链接的令牌,我可以在我的管理员中看到它(主页>验证令牌>令牌)
如果我删除了
@login_required
我可以@login_required
地访问家。 如何通过邮递员发送请求以使用我的令牌访问该资源?I am using django-rest-social-auth package to allow users authenticate in my Django rest app. I was able to retrieve a token from facebook for an user. Now, I don't know how to use that token. I am trying to access an endpoint that requires logged in users, but I see accesses only as anonymous user when I debug. I've been googleing this issue and tried a lot of different methods (different cookies, url params, etc.).
This is my particular case:
views.py
@login_required def home(request): return render(request, 'home.html')
I obtained my token calling http://localhost:8000/api/login/social/token/ (I was following the django-rest-social-auth readme) and it looks like:
{"token": "4571b2dce1f3abec34b28a4c7bd981c248a30698"}
I have that token linked with my user and I can see it in my admin (Home › Auth Token › Tokens)
If I delete the
@login_required
I can access home without any issue. How can I send a request via postman to access that resource using my token?
原文:https://stackoverflow.com/questions/43298633
最满意答案
您可以使用File方法的第三个参数来指定文件名。 当用户导航到此操作时,这将使
Content-Disposition
HTTP响应标头设置为attachment
弹出“另存为”对话框:public ActionResult DownloadFile(string fileId) { byte[] file = ... // TODO: adjust the MIME type and filename extension to your case accordingly return File(file, "text/plain", "foo.txt"); }
然后:
var id = '1234'; window.location.href = '<%= Url.Action("DownloadFile", "Home") %>?fileId=' + id;
会工作得很好。
You could use the third argument of the File method to specify a filename. This will have as an effect to set the
Content-Disposition
HTTP response header toattachment
popping a Save As dialog when the user navigates to this action:public ActionResult DownloadFile(string fileId) { byte[] file = ... // TODO: adjust the MIME type and filename extension to your case accordingly return File(file, "text/plain", "foo.txt"); }
Then:
var id = '1234'; window.location.href = '<%= Url.Action("DownloadFile", "Home") %>?fileId=' + id;
will work just fine.
相关问答
更多-
通过本地客户端程序获取服务器mysql数据库信息[2023-04-27]
ajax -
将SaveAs2对话框文件类型与Application.FileDialog匹配(Match SaveAs2 Dialog File Type To Application.FileDialog)[2024-03-22]
我很惊讶SaveAs2会给你一个诚实的提示 - 只有一个新文件和.Save会带给你那个提示。 如果要获得与该提示类似的内容,可以使用类型为msoFileDialogSaveAs的 Application.FileDialog 。 使用下面的代码(可能作为AddIn适合更多): Option Explicit Sub MySaveAs() Dim oPrompt As FileDialog, i As Long, sFilename As String Set oPrompt = Appli ... -
在成功函数内部,'this'不指向对话框对象。 您可能必须将对话框对象存储在另一个变量中,如下所示 "Delete": function() { var that = this; $.ajax ({ url:"util.php", data:"q=0&f=delete&save_id="+save_id, ...
-
为什么不在打开文档之前创建文档的副本? 例如,假设您要使用脚本修改c:\ docs \ myfile.docx,并且希望将修改后的版本保存为c:\ newdocs \ newfile.docx。 在脚本中打开Word之前,请执行File.Move(“c:\ docs \ myfile.docx”,“c:\ newdocs \ newfile.docx”); 然后打开目标文件,进行更改,并执行document.Save(); Why not create a copy of the document befo ...
-
您可以按此处所述单击按钮。 https://msdn.microsoft.com/VBA/Office-Shared-VBA/articles/commandbars-executemso-method-office Private Sub SaveAllAttachments_ExecuteMso() Dim objItem As Object Dim objInsp As Inspector Set objItem = ActiveInspector.currentItem Set objInsp ...
-
我发现最简单的解决方案是返回一个 秒/ cmd_process.php $handle = fopen('log_'.time().'.txt','w+'); fwrite($handle, $data); echo "Please wait wh ...
-
您的第一个请求应该只在您的服务器上创建zip文件并返回一个链接来访问它。 在客户端站点上收到该链接后,只需执行它即可。 这样,一切都会按照您的意愿发生,因为它将是一个常规的文件下载。 并且很快下载完成,您可以再次删除该文件。 Your first request should only create the zip file on your server and return a link to reach it. After you received that link on the client sit ...
-
VBA SaveAs方法(VBA SaveAs Method)[2022-07-22]
您的日期中包含非法字符 。 用破折号而不是斜杠格式化日期,这不会发生。 The following reserved characters: < (less than) > (greater than) : (colon) " (double quote) / (forward slash) \ (backslash) | (vertical bar or pipe) ? (question mark) * (asterisk) Y ... -
您可以使用File方法的第三个参数来指定文件名。 当用户导航到此操作时,这将使Content-Disposition HTTP响应标头设置为attachment弹出“另存为”对话框: public ActionResult DownloadFile(string fileId) { byte[] file = ... // TODO: adjust the MIME type and filename extension to your case accordingly return ...
-
像这样,不要忘记像我添加的Marshal类一样处理com对象。 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Dim xls As New Microsoft.Office.Interop.Excel.Application Dim xlsWorkBook As Microsoft.Office.Interop.Excel.Workbook Dim xlsW ...