Giter Site home page Giter Site logo

Comments (4)

blueww avatar blueww commented on August 24, 2024

@juliusl

"getUserDelegationKey" only support Oauth (Microsoft Entra ID) authentication. This is same in both product Azure and Azurite.
However, you are trying to call it with sharedkey authentication so the failure happen, this is by design in both product Azure and Azurite.
See more details in the rest API doc and feature doc:
https://learn.microsoft.com/en-us/rest/api/storageservices/get-user-delegation-key#authorization
https://learn.microsoft.com/en-us/rest/api/storageservices/create-user-delegation-sas

BTW, to enable Oauth authentication with Azurite, you need to start Azurite with https and Oauth configuration, see https://github.com/Azure/Azurite?tab=readme-ov-file#oauth-configuration
And for Oauth, Azurite will do basic authentication, like validating incoming bearer token, checking issuer, audience, expiry. But Azurite will NOT check token signature and permission.

I will close this issue as it's by design.
Feel free to contact us again if you need any further assistance on Azurite.

from azurite.

juliusl avatar juliusl commented on August 24, 2024

@blueww

BTW, to enable Oauth authentication with Azurite, you need to start Azurite with https and Oauth configuration, see https://github.com/Azure/Azurite?tab=readme-ov-file#oauth-configuration
And for Oauth, Azurite will do basic authentication, like validating incoming bearer token, checking issuer, audience, expiry. But Azurite will NOT check token signature and permission.

Can you give me an example of how to create a test blob client w/ oauth instead of using the emulator connection string?

from azurite.

juliusl avatar juliusl commented on August 24, 2024

I ended up w/ this, is this what you meant?

// See https://aka.ms/new-console-template for more information
using Azure.Core;
using Azure.Storage.Blobs;

Console.WriteLine("Hello, World!");


var client = new BlobServiceClient(new Uri(@"https://localhost:10000/devstoreaccount1"), new TestTokenCredentials());

var key = await client.GetUserDelegationKeyAsync(DateTimeOffset.UtcNow, DateTimeOffset.UtcNow.AddDays(10));


Console.WriteLine(key);

return;

class TestTokenCredentials : TokenCredential
{
    public TestTokenCredentials()
    {
    }

    public override AccessToken GetToken(TokenRequestContext requestContext, CancellationToken cancellationToken)
    {
        return new AccessToken("test", DateTimeOffset.UtcNow.AddDays(1));
    }

    public override ValueTask<AccessToken> GetTokenAsync(TokenRequestContext requestContext, CancellationToken cancellationToken)
    {
        return ValueTask.FromResult(new AccessToken("test", DateTimeOffset.UtcNow.AddDays(1)));
    }
}

from azurite.

blueww avatar blueww commented on August 24, 2024

I ended up w/ this, is this what you meant?

// See https://aka.ms/new-console-template for more information
using Azure.Core;
using Azure.Storage.Blobs;

Console.WriteLine("Hello, World!");


var client = new BlobServiceClient(new Uri(@"https://localhost:10000/devstoreaccount1"), new TestTokenCredentials());

var key = await client.GetUserDelegationKeyAsync(DateTimeOffset.UtcNow, DateTimeOffset.UtcNow.AddDays(10));


Console.WriteLine(key);

return;

class TestTokenCredentials : TokenCredential
{
    public TestTokenCredentials()
    {
    }

    public override AccessToken GetToken(TokenRequestContext requestContext, CancellationToken cancellationToken)
    {
        return new AccessToken("test", DateTimeOffset.UtcNow.AddDays(1));
    }

    public override ValueTask<AccessToken> GetTokenAsync(TokenRequestContext requestContext, CancellationToken cancellationToken)
    {
        return ValueTask.FromResult(new AccessToken("test", DateTimeOffset.UtcNow.AddDays(1)));
    }
}

We are Azurite owner, but not .net SDK expert, so might not be the best person to give the usage of .net SDK.
Here's a .net SDK example for you reference.
https://learn.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-dotnet?tabs=visual-studio%2Cmanaged-identity%2Croles-azure-portal%2Csign-in-visual-studio%2Cidentity-visual-studio&pivots=blob-storage-quickstart-scratch#sign-in-and-connect-your-app-code-to-azure-using-defaultazurecredential

For your above code, it might not work with Azurite, since Azurite will do some basic validation on the token (see details). So use string like "test" as the token won't pass validation in Azurite.

And you must start Azurite with Oauth configuration to support Oauth credential.

from azurite.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.