简体   繁体   English

请求 Header 获得 Token + Email 授权

[英]Request Header for Token + Email Authorization

I'm trying to use an API with token authorization.我正在尝试使用带有令牌授权的 API。

In their documentation it says:在他们的文档中它说:

Every request should contain an Authorization header with the api credentials like this: Authorization: Token token="abc123", email="reseller@example.com"每个请求都应包含授权 header 和 api 凭据,如下所示: Authorization: Token token="abc123", email="reseller@example.com"

I'm unsure how exactly I need to set my headers, I have tried this我不确定我需要如何设置我的标题,我试过这个

try {
  const res = await fetch("https://pokamax.com/apis/reseller/v1/orders", {
    method: "get",
    headers: new Headers({
      Authorization: 'Token token="mytoken", email="my@email.com',
      // Authorization: "Bearer mytoken"
    })
  });
  console.log("Res", res);
} catch (error) {
  console.error("Error", error);
}

But it won't work.但它不会起作用。 How do I need to set my headers?我需要如何设置标题?

I'm not 100% sure, because I can't read the original docs, but most headers would follow a format similar to:我不是 100% 确定,因为我无法阅读原始文档,但大多数标题会遵循类似于以下的格式:

headers: new Headers({ 
        Authorization: { 
             'Token': 'token="mytoken", email="my@email.com'' 
                       } 
                })

Give it a shot, maybe it'll work.试一试,也许会奏效。

According with [1] Authorization header must have the following structure:根据 [1] 授权 header 必须具有以下结构:

Authorization: <type> <credentials>

Token and email are not allowed types on this header as MDN says [2].正如 MDN 所说 [2],在此 header 上不允许使用Tokenemail类型。 I think the docs of the API doesn't give enough information about this.我认为 API 的文档没有提供足够的信息。 I think the email could be a separate custom header.我认为 email 可能是一个单独的定制 header。 I'm not sure this will work as I don't not how the API works but check if this work:我不确定这是否可行,因为我不知道 API 是如何工作的,但请检查这是否可行:

try {
  const res = await fetch("https://pokamax.com/apis/reseller/v1/orders", {
    method: "get",
    headers: new Headers({
      Authorization: 'Bearer mytoken',
      email: 'my@email.com'
    })
  });
  console.log("Res", res);
} catch (error) {
  console.error("Error", error);
}

[1] - https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization [1] - https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization

[2] - https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication#authentication_schemes [2] - https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication#authentication_schemes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM