是否可以在 Azure 之外使用 Azure 共享访问签名?

问题描述

由于 Azures Shared Access Signatures (SAS)一个开放标准,我想在我的 Django 应用程序中使用它,该应用程序与 Azure 没有任何链接。我基本上想创建一段代码,在我提供的特定 url 上创建接下来 24 小时的读取权限。所以我在 SAS 上观看了一些视频,并为其安装了 python 库 (pip install azure-storage-blob)。

我阅读了 README here on github,但据我所知,它始终需要一个 Azure 帐户。是否也可以在我自己的(Python)应用程序中使用 SAS?我想象它基于预定义的密钥创建哈希。如果这是可能的,是否有人有任何关于如何创建 url 以及如何验证它的示例代码?最好使用 Python,但也欢迎使用其他语言的示例代码

解决方法

虽然原始 blob 存储 sas 生成代码存在 here,但我更愿意发现以下简化代码对您的一般用途更有用(受 this sample 启发)。 根据您的需要进行调整。下面是使用密钥的客户端 sas 生成逻辑(hmac sha256 摘要)。在服务器端使用类似的逻辑重新生成签名提取 URL 参数 (sr,sig,se) 并将相同的 (sig) 与从客户端传递的参数进行比较以进行匹配。注意客户端和服务器端的共享密钥是这里的主要驱动因素。

<html>
<head lang="en">
    <meta charset="UTF-8">
    <style>
        body {
            margin: 0;
            padding: 0;
            background: url() no-repeat;
            background-size: cover;
            font-family: sans-serif;
            background-image: url(image/hbg.gif)
        }

        .topnav {
            overflow: hidden;
            background-color: whitesmoke;
        }

            .topnav a {
                float: left;
                color: black;
                text-align: center;
                padding: 14px 16px;
                text-decoration: none;
                font-size: 17px;
            }

                .topnav a:hover {
                    background-color: white;
                    color: black;
                }

                .topnav a.active {
                    background-color: black;
                    color: white;
                }

        .register-box {
            width: 380px;
            height: 480px;
            position: relative;
            margin: 6% auto;
            background-color: whitesmoke;
            padding: 5px;
        }

        .userinput-box {
            width: 100%;
            padding: 10px 0;
            margin: 5px 0;
            border-left: 0;
            border-top: 0;
            border-right: 0;
            border-bottom: 1px;
            outline: none;
            background: transparent;
        }

        .userinput-group {
            top: 180px;
            position: absolute;
            width: 280px;
        }

        .button {
            background-color: #cbcbcb;
        }
    </style>
    <script src="server.js"></script>
</head>
<body>
    <div class="topnav">
        <a class="active" href="../Subpages/account.html">Log in</a>
        <a href="https://exampletonyhuang.azurewebsites.net/">Home</a>
        <a href="#news">News</a>
        <a href="#contact">Contact</a>
        <a href="#about">About</a>
        <a href="../Subpages/shoppingcart.html">Shopping Cart</a>
        <a href="../Subpages/billinginfo.html">Billing info</a>
    </div>
    <div class="register-box">

        <br /><br /><center><h1><b>Register Account</b></h1></center>

        <form class="userinput-box">
            <center>
                <h3>Email: <input type="text" name="email" id="email" required></h3>
                <br /><h3>Username: <input type="text" name="username" id="username" required></h3>
                <br /><h3>Password: <input type="password" name="password" id="password" required></h3>
            </center>
        </form>
        <center>
            <input type="submit" class="button" onclick="insertdatabase()">
            <br />
                
        </center>
    </div>
</body>
</html>