gpt4 book ai didi

open-liberty - 如何配置 OAuth 授权 URL

转载 作者:行者123 更新时间:2023-12-02 00:55:47 25 4
gpt4 key购买 nike

我有一个 JAX-RS 应用程序,它使用 MP-OpenApi 来提供一个使用 OpenLiberty 的 OpenAPI UI。我的 API 使用 OAuth2 隐式流进行身份验证。这是当前使用注释配置的,如下所示:

@SecurityScheme(
securitySchemeName = JaxRsApplication.OAUTH2_SECURITY_SCHEME_NAME,
type = SecuritySchemeType.OAUTH2,
flows = @OAuthFlows(
implicit = @OAuthFlow(
authorizationUrl = "https://auth-server/connect/authorize",
scopes = @OAuthScope(name = "some-api-scope", description = "Some API Scope"))))

我的目标是在配置文件中配置 authorizationUrl 值,而不是在注释中对其进行硬编码,以便我可以将它配置为不同的服务器环境作为 CI/CD 步骤。这能做到吗?

另外,有没有办法选择一些范围并在 OpenAPI UI 中自动填充客户端 ID?

干杯。

最佳答案

覆盖 URL

关于Microprofile OpenAPI Spec: OASFilter ,我们可以覆盖 authorizationUrl如下例:-

package my.filter;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;

import org.eclipse.microprofile.openapi.OASFilter;
import org.eclipse.microprofile.openapi.models.security.SecurityScheme;

public class DemoOASFilter implements OASFilter {
@Override
public SecurityScheme filterSecurityScheme(final SecurityScheme securityScheme) {
Config config = ConfigProvider.getConfig();
String myUrl = config.getValue("my.url",
String.class);
securityScheme.getFlows().
getImplicit().
setAuthorizationUrl(myUrl);

return securityScheme;
}
}

然后把我们的全限定类名作为 mp.openapi.filter 的值在 META-INF/microprofile-config.properties如下例
mp.openapi.filter=my.filter.DemoOASFilter
my.url=http://some/url

不仅要覆盖 authorizationUrl , OAuthFlow还提供我们覆盖 tokenUrl , refreshUrl等等。除了 implicit , OAuthFlows还提供 authorizationCode , clientCredentails和其他人也是如此。此外 OASFilter界面让我们覆盖更多,例如 APIResponse , tag , server等等。

Microprofile: Config 集成

Config config = ConfigProvider.getConfig();
String myUrl = config.getValue("my.url",
String.class);

我试图将 URL 配置放到 META-INF/microprofile-config.properties如上面的例子,但没有实现,因为它给了我一个 java.util.NoSuchElementException .

反正 environment variablesystem properties达到。

docker run -it \
--env my.url=http://some/url \
....

java -Dmy.url=http://some/url -jar ....

关于open-liberty - 如何配置 OAuth 授权 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54394218/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com