pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  • <small id='wUx3e'></small><noframes id='wUx3e'>

      <legend id='wUx3e'><style id='wUx3e'><dir id='wUx3e'><q id='wUx3e'></q></dir></style></legend>

        <i id='wUx3e'><tr id='wUx3e'><dt id='wUx3e'><q id='wUx3e'><span id='wUx3e'><b id='wUx3e'><form id='wUx3e'><ins id='wUx3e'></ins><ul id='wUx3e'></ul><sub id='wUx3e'></sub></form><legend id='wUx3e'></legend><bdo id='wUx3e'><pre id='wUx3e'><center id='wUx3e'></center></pre></bdo></b><th id='wUx3e'></th></span></q></dt></tr></i><div class="rdjv9hp" id='wUx3e'><tfoot id='wUx3e'></tfoot><dl id='wUx3e'><fieldset id='wUx3e'></fieldset></dl></div>

          <bdo id='wUx3e'></bdo><ul id='wUx3e'></ul>
      1. <tfoot id='wUx3e'></tfoot>
      2. 使用 JavaScript 的基本身份驗證

        Basic Authentication Using JavaScript(使用 JavaScript 的基本身份驗證)

        • <tfoot id='dq2rN'></tfoot>
            • <legend id='dq2rN'><style id='dq2rN'><dir id='dq2rN'><q id='dq2rN'></q></dir></style></legend>

              <small id='dq2rN'></small><noframes id='dq2rN'>

                  <tbody id='dq2rN'></tbody>
                  <bdo id='dq2rN'></bdo><ul id='dq2rN'></ul>

                • <i id='dq2rN'><tr id='dq2rN'><dt id='dq2rN'><q id='dq2rN'><span id='dq2rN'><b id='dq2rN'><form id='dq2rN'><ins id='dq2rN'></ins><ul id='dq2rN'></ul><sub id='dq2rN'></sub></form><legend id='dq2rN'></legend><bdo id='dq2rN'><pre id='dq2rN'><center id='dq2rN'></center></pre></bdo></b><th id='dq2rN'></th></span></q></dt></tr></i><div class="vr5ph7v" id='dq2rN'><tfoot id='dq2rN'></tfoot><dl id='dq2rN'><fieldset id='dq2rN'></fieldset></dl></div>
                • 本文介紹了使用 JavaScript 的基本身份驗證的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在構建一個使用 Caspio 的應用程序API.我在針對他們的 API 進行身份驗證時遇到了一些問題.我花了 2-3 天試圖弄清楚這一點,但這可能是由于我的一些理解.我已經閱讀了無數關于stackoverflow帖子的文章,但還沒有解決這個問題.下面是我的解決方案的代碼示例,基于我所查看的內容,我收到了 400 狀態代碼消息;我在這里做錯了什么?(請提供注釋良好的代碼示例,我希望在此處發布引用其他材料的鏈接,因為我已經廣泛查看了這些材料.謝謝!):

                  我看過的一些參考資料:

                  1) 用于 HTTP 基本身份驗證的純 JavaScript 代碼?

                  2) 如何在從 javascript 調用 REST API 中進行 http 身份驗證

                  我想使用下面 caspio 描述的這種身份驗證方法:

                  作為在請求正文中包含憑據的替代方法,客戶端可以使用 HTTP 基本身份驗證方案.在這種情況下,將通過以下方式設置身份驗證請求:

                  方法: POST

                  網址:您的令牌端點

                  正文:grant_type=client_credentials

                  標頭參數:

                  授權:基本基本身份驗證領域

                  以下是我的 Javascript 和 HTML 代碼.

                  JavaScript:

                  var userName = "clientID";var passWord = "secretKey";功能驗證用戶(用戶,密碼){var token = 用戶 + ":" + 密碼;//我應該編碼這個值嗎??????有關系嗎???//Base64 編碼 ->BTOAvar hash = btoa(token);返回基本"+哈希;}函數 CallWebAPI() {//新的 XMLHTTPRequestvar request = new XMLHttpRequest();request.open("POST", "https://xxx123.casio.com/oauth/token", false);request.setRequestHeader("授權", authenticateUser(userName, passWord));請求.發送();//查看請求狀態警報(請求.狀態);response.innerHTML = request.responseText;}

                  HTML:

                  <div id="響應"></div>

                  解決方案

                  在花了相當多的時間研究這個之后,我想出了解決方案;在這個解決方案中,我沒有使用基本身份驗證,而是使用 oAuth 身份驗證協議.但是要使用基本身份驗證,您應該能夠在setHeaderRequest"中指定這一點,只需對代碼示例的其余部分進行最少的更改.我希望這將能夠在未來對其他人有所幫助:

                  var token_//變量將存儲令牌var userName = "clientID";//應用客戶端IDvar passWord = "secretKey";//應用程序客戶端秘密var caspioTokenUrl = "https://xxx123.caspio.com/oauth/token";//您的應用程序令牌端點var request = new XMLHttpRequest();函數 getToken(url, clientID, clientSecret) {變量鍵;request.open("POST", url, true);request.setRequestHeader("內容類型", "應用程序/json");request.send("grant_type=client_credentials&client_id="+clientID+"&"+"client_secret="+clientSecret);//指定憑據以在請求時接收令牌request.onreadystatechange = function () {如果(request.readyState == request.DONE){var response = request.responseText;var obj = JSON.parse(response);鍵 = obj.access_token;//存儲accesstoken的值令牌_ =鍵;//將令牌存儲在全局變量token_"中,或者您可以簡單地從函數中返回訪問令牌的值}}}//獲取令牌getToken(casioTokenUrl, 用戶名, 密碼);

                  如果您在某些請求上使用 Caspio REST API,您可能必須為對端點的某些請求編碼參數;請參閱有關此問題的 Caspio 文檔;

                  注意:encodedParams 未在此示例中使用,但在我的解決方案中使用.

                  現在您已經從令牌端點存儲了令牌,您應該能夠成功地對來自應用程序的 caspio 資源端點的后續請求進行身份驗證

                  function CallWebAPI() {var request_ = new XMLHttpRequest();var encodedParams = encodeURIComponent(params);request_.open("GET", "https://xxx123.casio.com/rest/v1/tables/", true);request_.setRequestHeader("授權", "承載"+ token_);request_.send();request_.onreadystatechange = function () {if (request_.readyState == 4 && request_.status == 200) {var response = request_.responseText;var obj = JSON.parse(response);//根據需要處理數據...}}}

                  此解決方案只考慮如何在純 javascript 中使用 Caspio API 成功發出經過身份驗證的請求.我敢肯定還有很多缺陷......

                  I am building an application that consumes the Caspio API. I am having some trouble authenticating against their API. I have spent 2-3 days trying to figure this out but it may be due to some understanding on my end. I have read countless articles on stackoverflow post and otherwise but have not solved the issue. Below is a code example of my solution based on what i have looked at and i am getting a 400 Status code message; What am i doing wrong here? (Please provide well commented code example and i would prefer to NOT have links posted here referencing other material as i have looked at these extensively. Thanks!):

                  Some references i have looked at:

                  1) Pure JavaScript code for HTTP Basic Authentication?

                  2) How to make http authentication in REST API call from javascript

                  I would like to use this authentication method as described by caspio below:

                  As an alternative to including credentials in the request body, a client can use the HTTP Basic authentication scheme. In this case, authentication request will be setup in the following way:

                  Method: POST

                  URL: Your token endpoint

                  Body: grant_type=client_credentials

                  Header parameter:

                  Authorization: Basic Basic authentication realm

                  Below are my Javascript and HTML code.

                  JavaScript:

                  var userName = "clientID";
                  var passWord = "secretKey";
                  
                  function authenticateUser(user, password)
                  {
                      var token = user + ":" + password;
                  
                      // Should i be encoding this value????? does it matter???
                      // Base64 Encoding -> btoa
                      var hash = btoa(token); 
                  
                      return "Basic " + hash;
                  }
                  
                  function CallWebAPI() {
                  
                      // New XMLHTTPRequest
                      var request = new XMLHttpRequest();
                      request.open("POST", "https://xxx123.caspio.com/oauth/token", false);
                      request.setRequestHeader("Authorization", authenticateUser(userName, passWord));  
                      request.send();
                      // view request status
                      alert(request.status);
                      response.innerHTML = request.responseText;
                  }
                  

                  HTML:

                  <div>
                  <div id="response">
                  
                  </div>
                  <input type="button" class="btn btn-primary" value="Call Web API" onclick="javascript:CallWebAPI();" />
                  

                  解決方案

                  After Spending quite a bit of time looking into this, i came up with the solution for this; In this solution i am not using the Basic authentication but instead went with the oAuth authentication protocol. But to use Basic authentication you should be able to specify this in the "setHeaderRequest" with minimal changes to the rest of the code example. I hope this will be able to help someone else in the future:

                  var token_ // variable will store the token
                  var userName = "clientID"; // app clientID
                  var passWord = "secretKey"; // app clientSecret
                  var caspioTokenUrl = "https://xxx123.caspio.com/oauth/token"; // Your application token endpoint  
                  var request = new XMLHttpRequest(); 
                  
                  function getToken(url, clientID, clientSecret) {
                      var key;           
                      request.open("POST", url, true); 
                      request.setRequestHeader("Content-type", "application/json");
                      request.send("grant_type=client_credentials&client_id="+clientID+"&"+"client_secret="+clientSecret); // specify the credentials to receive the token on request
                      request.onreadystatechange = function () {
                          if (request.readyState == request.DONE) {
                              var response = request.responseText;
                              var obj = JSON.parse(response); 
                              key = obj.access_token; //store the value of the accesstoken
                              token_ = key; // store token in your global variable "token_" or you could simply return the value of the access token from the function
                          }
                      }
                  }
                  // Get the token
                  getToken(caspioTokenUrl, userName, passWord);
                  

                  If you are using the Caspio REST API on some request it may be imperative that you to encode the paramaters for certain request to your endpoint; see the Caspio documentation on this issue;

                  NOTE: encodedParams is NOT used in this example but was used in my solution.

                  Now that you have the token stored from the token endpoint you should be able to successfully authenticate for subsequent request from the caspio resource endpoint for your application

                  function CallWebAPI() {
                      var request_ = new XMLHttpRequest();        
                      var encodedParams = encodeURIComponent(params);
                      request_.open("GET", "https://xxx123.caspio.com/rest/v1/tables/", true);
                      request_.setRequestHeader("Authorization", "Bearer "+ token_);
                      request_.send();
                      request_.onreadystatechange = function () {
                          if (request_.readyState == 4 && request_.status == 200) {
                              var response = request_.responseText;
                              var obj = JSON.parse(response); 
                              // handle data as needed... 
                  
                          }
                      }
                  } 
                  

                  This solution does only considers how to successfully make the authenticated request using the Caspio API in pure javascript. There are still many flaws i am sure...

                  這篇關于使用 JavaScript 的基本身份驗證的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調用 abort (jQuery) 之后,瀏覽器也會等待 ajax 調用完成)
                  JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不適用于 IE?)
                  XMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 無法加載,請求的資源上不存在“Access-Control-Allow-Origin標頭) - IT屋-程序員軟件開發技術分
                  Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請求是否有可能不遵循重定向 (301 302))
                  NETWORK_ERROR: XMLHttpRequest Exception 101(NETWORK_ERROR:XMLHttpRequest 異常 101)
                  XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內容)

                  <tfoot id='sni04'></tfoot>
                  <legend id='sni04'><style id='sni04'><dir id='sni04'><q id='sni04'></q></dir></style></legend>
                  <i id='sni04'><tr id='sni04'><dt id='sni04'><q id='sni04'><span id='sni04'><b id='sni04'><form id='sni04'><ins id='sni04'></ins><ul id='sni04'></ul><sub id='sni04'></sub></form><legend id='sni04'></legend><bdo id='sni04'><pre id='sni04'><center id='sni04'></center></pre></bdo></b><th id='sni04'></th></span></q></dt></tr></i><div class="7djrxvh" id='sni04'><tfoot id='sni04'></tfoot><dl id='sni04'><fieldset id='sni04'></fieldset></dl></div>

                    <tbody id='sni04'></tbody>

                      <bdo id='sni04'></bdo><ul id='sni04'></ul>

                        <small id='sni04'></small><noframes id='sni04'>

                            主站蜘蛛池模板: 槽钢冲孔机,槽钢三面冲,带钢冲孔机-山东兴田阳光智能装备股份有限公司 | 测试治具|过炉治具|过锡炉治具|工装夹具|测试夹具|允睿自动化设备 | 济南画室培训-美术高考培训-山东艺霖艺术培训画室 | atcc网站,sigma试剂价格,肿瘤细胞现货,人结肠癌细胞株购买-南京科佰生物 | 武汉森源蓝天环境科技工程有限公司-为环境污染治理提供协同解决方案 | 玻璃钢型材-玻璃钢风管-玻璃钢管道,生产厂家-[江苏欧升玻璃钢制造有限公司] | 金属切削液-脱水防锈油-电火花机油-抗磨液压油-深圳市雨辰宏业科技发展有限公司 | 河南砖机首页-全自动液压免烧砖机,小型砌块水泥砖机厂家[十年老厂] | 洗地机-全自动/手推式洗地机-扫地车厂家_扬子清洁设备 | 车间除尘设备,VOCs废气处理,工业涂装流水线,伸缩式喷漆房,自动喷砂房,沸石转轮浓缩吸附,机器人喷粉线-山东创杰智慧 | 论文查重_免费论文查重_知网学术不端论文查重检测系统入口_论文查重软件 | 口臭的治疗方法,口臭怎么办,怎么除口臭,口臭的原因-口臭治疗网 | 气体检测仪-氢气检测仪-可燃气体传感器-恶臭电子鼻-深国安电子 | 北京遮阳网-防尘盖土网-盖土草坪-迷彩网-防尘网生产厂家-京兴科技 | 切铝机-数控切割机-型材切割机-铝型材切割机-【昆山邓氏精密机械有限公司】 | 水性绝缘漆_凡立水_绝缘漆树脂_环保绝缘漆-深圳维特利环保材料有限公司 | 电动不锈钢套筒阀-球面偏置气动钟阀-三通换向阀止回阀-永嘉鸿宇阀门有限公司 | 不锈钢电动球阀_气动高压闸阀_旋塞疏水调节阀_全立阀门-来自温州工业阀门巨头企业 | 复合土工膜厂家|hdpe防渗土工膜|复合防渗土工布|玻璃纤维|双向塑料土工格栅-安徽路建新材料有限公司 | 皮带式输送机械|链板式输送机|不锈钢输送机|网带输送机械设备——青岛鸿儒机械有限公司 | 体感VRAR全息沉浸式3D投影多媒体展厅展会游戏互动-万展互动 | 西安文都考研官网_西安考研辅导班_考研培训机构_西安在职考研培训 | 小程序开发公司_APP开发多少钱_软件开发定制_微信小程序制作_客户销售管理软件-济南小溪畅流网络科技有限公司 | led冷热冲击试验箱_LED高低温冲击试验箱_老化试验箱-爱佩百科 | vr安全体验馆|交通安全|工地安全|禁毒|消防|安全教育体验馆|安全体验教室-贝森德(深圳)科技 | 液氨泵,液化气泵-淄博「亚泰」燃气设备制造有限公司 | 全国国际化学校_国际高中招生_一站式升学择校服务-国际学校网 | 骁龙云呼电销防封号系统-axb电销平台-外呼稳定『免费试用』 | 活性氧化铝球|氧化铝干燥剂|分子筛干燥剂|氢氧化铝粉-淄博同心材料有限公司 | 芝麻黑-芝麻黑石材厂家-永峰石业| 定制液氮罐_小型气相液氮罐_自增压液氮罐_班德液氮罐厂家 | 单锥双螺旋混合机_双螺旋锥形混合机-无锡新洋设备科技有限公司 | 网站建设-临朐爱采购-抖音运营-山东兆通网络科技 | 智能终端_RTU_dcm_北斗星空自动化科技 | 澳门精准正版免费大全,2025新澳门全年免费,新澳天天开奖免费资料大全最新,新澳2025今晚开奖资料,新澳马今天最快最新图库-首页-东莞市傲马网络科技有限公司 | 杜康白酒加盟_杜康酒代理_杜康酒招商加盟官网_杜康酒厂加盟总代理—杜康酒神全国运营中心 | 智慧钢琴-电钢琴-便携钢琴-数码钢琴-深圳市特伦斯乐器有限公司 | 中国品牌门窗网_中国十大门窗品牌_著名门窗品牌 | 房在线-免费房产管理系统软件-二手房中介房屋房源管理系统软件 | 安平县鑫川金属丝网制品有限公司,声屏障,高速声屏障,百叶孔声屏障,大弧形声屏障,凹凸穿孔声屏障,铁路声屏障,顶部弧形声屏障,玻璃钢吸音板 | 锤式粉碎机,医药粉碎机,锥式粉碎机-无锡市迪麦森机械制造有限公司 |