最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

multi tenant - Using quarkus OIDC Multitenancy, is it possible to extract tenantId from grpc call metadata? - Stack Overflow

programmeradmin1浏览0评论

I'm using TenantConfigResolver to set the tenantId dynamically

@ApplicationScoped
public class PartitionTenantResolver implements TenantConfigResolver {
@Override
public Uni<OidcTenantConfig> resolve(RoutingContext routingContext, OidcRequestContext<OidcTenantConfig> requestContext) {

    String dataPartitionId = routingContext.request().getHeader(DATA_PARTITION_ID);

    String keycloakUrl = ConfigProvider.getConfig().getValue("openid.provider.base-url", String.class);
    String clientId = ConfigProvider.getConfig().getValue("openid.provider.client-id", String.class);
    String secret = ConfigProvider.getConfig().getValue("openid.provider.secret", String.class);


    if (StringUtils.isNotEmpty(dataPartitionId)) {
        OidcTenantConfig config = new OidcTenantConfig();
        config.setAuthServerUrl(keycloakUrl + "/realms/" + dataPartitionId);
        config.setTenantId(dataPartitionId);
        config.setClientId(clientId);
        config.getCredentials().setSecret(secret);
        config.setApplicationType(OidcTenantConfig.ApplicationType.SERVICE);

        return Uni.createFrom().item(config);
    }
    return Uni.createFrom().nullItem();
}
}

This is work when using httpc request. How can I use the same strategy to extract tenantId from grpc call metadata in case of grpc service call?

I'm using TenantConfigResolver to set the tenantId dynamically

@ApplicationScoped
public class PartitionTenantResolver implements TenantConfigResolver {
@Override
public Uni<OidcTenantConfig> resolve(RoutingContext routingContext, OidcRequestContext<OidcTenantConfig> requestContext) {

    String dataPartitionId = routingContext.request().getHeader(DATA_PARTITION_ID);

    String keycloakUrl = ConfigProvider.getConfig().getValue("openid.provider.base-url", String.class);
    String clientId = ConfigProvider.getConfig().getValue("openid.provider.client-id", String.class);
    String secret = ConfigProvider.getConfig().getValue("openid.provider.secret", String.class);


    if (StringUtils.isNotEmpty(dataPartitionId)) {
        OidcTenantConfig config = new OidcTenantConfig();
        config.setAuthServerUrl(keycloakUrl + "/realms/" + dataPartitionId);
        config.setTenantId(dataPartitionId);
        config.setClientId(clientId);
        config.getCredentials().setSecret(secret);
        config.setApplicationType(OidcTenantConfig.ApplicationType.SERVICE);

        return Uni.createFrom().item(config);
    }
    return Uni.createFrom().nullItem();
}
}

This is work when using httpc request. How can I use the same strategy to extract tenantId from grpc call metadata in case of grpc service call?

Share Improve this question asked Feb 6 at 9:26 Bd GhnBd Ghn 31 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

When you set quarkus.grpc.server.use-separate-server=false, Quarkus supports multiple authentication mechanisms as documented here https://quarkus.io/guides/grpc-service-implementation#overview-of-supported-authentication-mechanisms. In regards to your TenantConfigResolver bean, gRPC is build on top of HTTP/2, therefore you don't need to (almost) change anything on your resolver. It should work out of the box. gRPC metadata are implemented using HTTP/2 headers, so try inspecting your headers.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论