"use strict";(self.webpackChunkelementary_public_docs=self.webpackChunkelementary_public_docs||[]).push([[11078],{15680:(e,t,n)=>{n.d(t,{xA:()=>l,yg:()=>y});var r=n(96540);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function s(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var c=r.createContext({}),p=function(e){var t=r.useContext(c),n=t;return e&&(n="function"==typeof e?e(t):s(s({},t),e)),n},l=function(e){var t=p(e.components);return r.createElement(c.Provider,{value:t},e.children)},m="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},d=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,c=e.parentName,l=i(e,["components","mdxType","originalType","parentName"]),m=p(n),d=a,y=m["".concat(c,".").concat(d)]||m[d]||u[d]||o;return n?r.createElement(y,s(s({ref:t},l),{},{components:n})):r.createElement(y,s({ref:t},l))}));function y(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,s=new Array(o);s[0]=d;var i={};for(var c in t)hasOwnProperty.call(t,c)&&(i[c]=t[c]);i.originalType=e,i[m]="string"==typeof e?e:a,s[1]=i;for(var p=2;p{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>s,default:()=>u,frontMatter:()=>o,metadata:()=>i,toc:()=>p});var r=n(58168),a=(n(96540),n(15680));const o={sidebar_position:3},s="\u8ba4\u8bc1",i={unversionedId:"developer-tools/cms/openapi/authentication",id:"developer-tools/cms/openapi/authentication",title:"\u8ba4\u8bc1",description:"\u670d\u52a1\u7aef\u4f7f\u7528 HMAC \u65b9\u5f0f\u8fdb\u884c\u8eab\u4efd\u8ba4\u8bc1\uff0c\u9700\u8981\u5728\u8bf7\u6c42Header\u4e2d\u989d\u5916\u6dfb\u52a0\u4e24\u4e2a\u5b57\u6bb5 X-Date \u548c Authorization\u3002",source:"@site/docs/developer-tools/cms/openapi/authentication.md",sourceDirName:"developer-tools/cms/openapi",slug:"/developer-tools/cms/openapi/authentication",permalink:"/help/docs/developer-tools/cms/openapi/authentication",draft:!1,editUrl:"https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/docs/developer-tools/cms/openapi/authentication.md",tags:[],version:"current",sidebarPosition:3,frontMatter:{sidebar_position:3},sidebar:"tutorialSidebar",previous:{title:"API\u6982\u89c8",permalink:"/help/docs/developer-tools/cms/openapi/ApiOverview"},next:{title:"\u5217\u51fa\u4eea\u8868\u677f",permalink:"/help/docs/developer-tools/cms/openapi/list-dashboard"}},c={},p=[],l={toc:p},m="wrapper";function u(e){let{components:t,...n}=e;return(0,a.yg)(m,(0,r.A)({},l,n,{components:t,mdxType:"MDXLayout"}),(0,a.yg)("h1",{id:"\u8ba4\u8bc1"},"\u8ba4\u8bc1"),(0,a.yg)("p",null,"\u670d\u52a1\u7aef\u4f7f\u7528 HMAC \u65b9\u5f0f\u8fdb\u884c\u8eab\u4efd\u8ba4\u8bc1\uff0c\u9700\u8981\u5728\u8bf7\u6c42Header\u4e2d\u989d\u5916\u6dfb\u52a0\u4e24\u4e2a\u5b57\u6bb5 ",(0,a.yg)("strong",{parentName:"p"},"X-Date")," \u548c ",(0,a.yg)("strong",{parentName:"p"},"Authorization"),"\u3002"),(0,a.yg)("pre",null,(0,a.yg)("code",{parentName:"pre",className:"language-bash"},'curl https://management.sensecoreapi.cn/monitor/ts/v1/subscriptions/{subscription_name}/resourceGroups/{resource_group_name}/zones/{zone}/telemetryStations \\\n -H \'X-Date: Wed, 26 Jul 2023 11:36:03 GMT\' \\\n -H \'Authorization: hmac accesskey="xxx", algorithm="hmac-sha256", headers="x-date", signature="m4b9mgep/FTiwTFutiqbwsemCjYxv3SUN9YZO7ZvKFc="\' \\\n ...\n')),(0,a.yg)("p",null,"\u7528\u6237\u9700\u8981\u5148\u4eceSenseCore\u7684",(0,a.yg)("a",{parentName:"p",href:"http://console.sensecore.cn"},"\u63a7\u5236\u53f0"),"\u9996\u9875\u83b7\u53d6AccessKey\u548cSecretKey\uff0c\u7136\u540e\u901a\u8fc7\u5982\u4e0b\u65b9\u5f0f\u8ba1\u7b97\u4e0a\u8ff0\u4e24\u4e2a\u5b57\u6bb5\u7684\u503c\u3002"),(0,a.yg)("p",null,(0,a.yg)("strong",{parentName:"p"},"bash/shell \u793a\u4f8b")),(0,a.yg)("pre",null,(0,a.yg)("code",{parentName:"pre",className:"language-bash"},'access_key=\'YOUR ACCESS KEY\'\nsecret_key=\'YOUR SECRET KEy\'\n\nxdate=$(date -u +"%a, %d %b %Y %H:%M:%S GMT")\ndata="x-date: ${xdate}"\n\nsign=$(echo -n "$data" | openssl dgst -sha256 -hmac "$secret_key" -binary | base64)\nauth="hmac accesskey=\\"${access_key}\\", algorithm=\\"hmac-sha256\\", headers=\\"x-date\\", signature=\\"${sign}\\""\n\necho "X-Date: $xdate"\necho "Authorization: $auth"\n\n')),(0,a.yg)("p",null,(0,a.yg)("strong",{parentName:"p"},"python \u793a\u4f8b")),(0,a.yg)("pre",null,(0,a.yg)("code",{parentName:"pre",className:"language-python"},'import hmac\nimport base64\nfrom hashlib import sha256\nfrom datetime import datetime\nfrom time import mktime\nfrom wsgiref.handlers import format_date_time\n\n\ndef gen_auth_header(access_key: str, secret_key: str):\n xdate = format_date_time(mktime(datetime.now().timetuple()))\n data = f\'x-date: {xdate}\'\n\n key = secret_key.encode(\'utf-8\')\n data = data.encode(\'utf-8\')\n sign = base64.b64encode(hmac.new(key, data, digestmod=sha256).digest()).decode(\'utf-8\')\n\n auth = f\'hmac accesskey="{access_key}", algorithm="hmac-sha256", headers="x-date", signature="{sign}"\'\n\n return {\n "X-Date": xdate,\n "Authorization": auth,\n }\n')))}u.isMDXComponent=!0}}]);