"use strict";(self.webpackChunkelementary_public_docs=self.webpackChunkelementary_public_docs||[]).push([[27742],{15680:(e,t,a)=>{a.d(t,{xA:()=>u,yg:()=>g});var n=a(96540);function r(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function o(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,n)}return a}function s(e){for(var t=1;t=0||(r[a]=e[a]);return r}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(r[a]=e[a])}return r}var c=n.createContext({}),p=function(e){var t=n.useContext(c),a=t;return e&&(a="function"==typeof e?e(t):s(s({},t),e)),a},u=function(e){var t=p(e.components);return n.createElement(c.Provider,{value:t},e.children)},l="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var a=e.components,r=e.mdxType,o=e.originalType,c=e.parentName,u=i(e,["components","mdxType","originalType","parentName"]),l=p(a),m=r,g=l["".concat(c,".").concat(m)]||l[m]||d[m]||o;return a?n.createElement(g,s(s({ref:t},u),{},{components:a})):n.createElement(g,s({ref:t},u))}));function g(e,t){var a=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var o=a.length,s=new Array(o);s[0]=m;var i={};for(var c in t)hasOwnProperty.call(t,c)&&(i[c]=t[c]);i.originalType=e,i[l]="string"==typeof e?e:r,s[1]=i;for(var p=2;p{a.r(t),a.d(t,{assets:()=>c,contentTitle:()=>s,default:()=>d,frontMatter:()=>o,metadata:()=>i,toc:()=>p});var n=a(58168),r=(a(96540),a(15680));const o={sidebar_position:3},s="\u8ba4\u8bc1\u6587\u6863",i={unversionedId:"cloud-foundation/storage/aoss/openapi/authentication",id:"cloud-foundation/storage/aoss/openapi/authentication",title:"\u8ba4\u8bc1\u6587\u6863",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/cloud-foundation/storage/aoss/openapi/authentication.md",sourceDirName:"cloud-foundation/storage/aoss/openapi",slug:"/cloud-foundation/storage/aoss/openapi/authentication",permalink:"/help/docs/cloud-foundation/storage/aoss/openapi/authentication",draft:!1,editUrl:"https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/docs/cloud-foundation/storage/aoss/openapi/authentication.md",tags:[],version:"current",sidebarPosition:3,frontMatter:{sidebar_position:3},sidebar:"tutorialSidebar",previous:{title:"API\u6982\u89c8",permalink:"/help/docs/cloud-foundation/storage/aoss/openapi/apis"},next:{title:"\u521b\u5efa\u5bf9\u8c61\u5b58\u50a8\u8d44\u6e90\u5305",permalink:"/help/docs/cloud-foundation/storage/aoss/openapi/create-pack"}},c={},p=[],u={toc:p},l="wrapper";function d(e){let{components:t,...a}=e;return(0,r.yg)(l,(0,n.A)({},u,a,{components:t,mdxType:"MDXLayout"}),(0,r.yg)("h1",{id:"\u8ba4\u8bc1\u6587\u6863"},"\u8ba4\u8bc1\u6587\u6863"),(0,r.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,r.yg)("strong",{parentName:"p"},"X-Date")," \u548c ",(0,r.yg)("strong",{parentName:"p"},"Authorization"),"\u3002"),(0,r.yg)("pre",null,(0,r.yg)("code",{parentName:"pre",className:"language-bash"},'curl https://management.sensecoreapi.dev/storage/aoss/v1/subscriptions/{subscription_name}/resourceGroups/{resource_group_name}/zones/{zone}/aossPack/{aoss_pack_name} \\\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')),(0,r.yg)("p",null,"\u7528\u6237\u9700\u8981\u5148\u4eceSenseCore\u7684",(0,r.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,r.yg)("p",null,(0,r.yg)("strong",{parentName:"p"},"bash\u793a\u4f8b")),(0,r.yg)("pre",null,(0,r.yg)("code",{parentName:"pre",className:"language-bash"},'access_key=\'YOUR ACCESS KEY\'\nsecret_key=\'YOUR SECRET KEy\'\n\nxdate=$(LC_TIME=en_US 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,r.yg)("blockquote",null,(0,r.yg)("p",{parentName:"blockquote"},"\u4e0a\u8ff0\u547d\u4ee4\u9700\u4f7f\u7528bash/zsh\u6267\u884c\uff0c\u82e5\u4f7f\u7528sh\u6267\u884c\uff0c\u5f97\u5230\u7684\u7b7e\u540d\u503c\u4f1a\u6709\u8bef")),(0,r.yg)("p",null,(0,r.yg)("strong",{parentName:"p"},"python \u793a\u4f8b")),(0,r.yg)("pre",null,(0,r.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')))}d.isMDXComponent=!0}}]);