AssumeRoleWithWebIdentity with MinIO #3711
-
I am using Keycloak with OpenID and MinIO. To be able to use MinIO from my c# client I need to retrieve temporary access credentials from the If I manually send the same HTTP request to MinIO, but remove the The call to var config = new AmazonSecurityTokenServiceConfig
{
ServiceURL = "http://localhost:19008",
};
var client = new AmazonSecurityTokenServiceClient("dummy", "dummy", config);
var request = new AssumeRoleWithWebIdentityRequest
{
DurationSeconds = 3600,
WebIdentityToken = "... OIDC access_token I get from Keycloak ...",
};
var response = await client.AssumeRoleWithWebIdentityAsync(request); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
@ceuser1 Good afternoon. Thanks for starting the discussion. You may try using a customer Below is the sample code: using Amazon.Runtime;
using Amazon.SecurityToken;
using Amazon.SecurityToken.Model;
Amazon.AWSConfigs.HttpClientFactory = new CustomHttpClientFactory();
var config = new AmazonSecurityTokenServiceConfig
{
ServiceURL = "http://localhost:19008",
};
var client = new AmazonSecurityTokenServiceClient("dummy", "dummy", config);
var request = new AssumeRoleWithWebIdentityRequest
{
DurationSeconds = 3600,
WebIdentityToken = "... OIDC access_token I get from Keycloak ...",
};
var testResponse = await client.AssumeRoleWithWebIdentityAsync(request);
class CustomHttpClientFactory : Amazon.Runtime.HttpClientFactory
{
public override HttpClient CreateHttpClient(IClientConfig clientConfig)
{
Console.WriteLine("Creating custom HttpClient");
var socketHandler = new SocketsHttpHandler();
var httpClient = new HttpClient(new CustomClientHandler { InnerHandler = socketHandler });
return httpClient;
}
}
class CustomClientHandler : DelegatingHandler
{
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
request.Headers.Remove("Authorization");
return base.SendAsync(request, cancellationToken);
}
} |
Beta Was this translation helpful? Give feedback.
@ceuser1 Good afternoon. Thanks for starting the discussion. You may try using a customer
HttpHandler
as demonstrated in video AWS re:Invent 2023 - Getting the most performance for your .NET apps from AWS SDK for .NET (XNT401).Below is the sample code: