身份验证

Print Portal 可配置为需要或不需要身份验证。启用身份验证后,必须从经过身份验证的用户发起请求,才能访问 Print Portal 资源。

有关如何发送身份验证请求的说明,请参阅以下步骤。启用 Print Portal 身份验证后,如果提交的用户名和密码正确无误,那么会返回成功响应,其中包含将来进行 REST API 调用时要使用的身份验证令牌。

关闭发送身份验证请求

  1. 打开 Print Portal Swagger 用户界面。要执行此操作,请将“/swagger/”添加到 Print Portal URL 中,如下所示:

    http://localhost/BarTender/swagger/

  2. 针对顶端项目“身份验证”单击“发布”,以显示请求的身份验证要求。

  3. 单击“试试看”。

  4. 添加用户名和密码。

  5. 单击“执行”。

关闭JavaScript 示例

复制
/*---------------------------------------------------------------------------------------------
Authenticate */

// This will allow the user to extract an authentication token

// Change the two variables to your credentials
let username = "domain\\username";
let password = "password";

// Change these to the URL
let basePrintPortalURL = "https://example.com/Bartender/";

// First step, authentication
fetch(basePrintPortalURL + 'Authenticate', {
  method: 'post',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
            "username": username,
            "password": password
  })
               })
//The response will be a JSON object which contains a token and expiration
.then(response => response.json())

.then(result => {
  console.log('Success:', result);
  //If successful, a token will be returned as the result
  // Token will be used on the header of print call using the header 'Authorization': 'Bearer ' + token
})
.catch(error => {
  console.error("The user name or password provided is incorrect.");
});