rajanadar / VaultSharp

A comprehensive cross-platform .NET Library for HashiCorp's Vault, a secret management tool
http://rajanadar.github.io/VaultSharp
Apache License 2.0
493 stars 134 forks source link

JWTAuthMethodProvider should pass unauthenticated: true for callback requests #348

Closed Stuv7CB closed 2 months ago

Stuv7CB commented 7 months ago

Describe the bug JWTAuthMethodProvider should pass unauthenticated: true for callback requests

VaultSharp Version v1.13.0.1

Vault Version Any version supporting oidc auth

Does this work with Vault CLI? Yes, using vault login -method=oidc

Sample Code Snippet Non-confidential snippet of code

        var authMethod = new CustomAuthMethodInfo("oidc", () => null));

        var client = new VaultSharp.VaultClient(new VaultClientSettings(vaultAddr, authMethod));

        var callbackUrl = await client.V1.Auth.JWT.GetOIDCAuthURLAsync(
            HttpLocalhostOidcCallback,
            mountPoint: "oidc");

Exception Details/Stack Trace/Error Message NRE as library calls _polymath.MakeVaultApiRequest with unauthenticated: false by default so library tries to obtain token which is null.

Any additional info As workaround it is possible to get callback url with following code, but this is very confusing

         var authMethod = new CustomAuthMethodInfo("oidc", () => Task.FromResult(new AuthInfo
        {
            ClientToken = "foo" // some nonsense
        }));

        var client = new VaultSharp.VaultClient(new VaultClientSettings(vaultAddr, authMethod));

        var callbackUrl = await client.V1.Auth.JWT.GetOIDCAuthURLAsync(
            HttpLocalhostOidcCallback,
            mountPoint: "oidc");