Merge pull request #7263 from HJianBo/fix-auth-jwt

fix(authn-jwt): accept the pem conntet to create jwk authenticator
This commit is contained in:
JianBo He 2022-03-11 15:06:43 +08:00 committed by GitHub
commit 85d1a4f9bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 1 deletions

View File

@ -215,7 +215,7 @@ create2(#{use_jwks := false,
algorithm := 'public-key',
certificate := Certificate,
verify_claims := VerifyClaims}) ->
JWK = jose_jwk:from_pem_file(Certificate),
JWK = create_jwk_from_pem_or_file(Certificate),
{ok, #{jwk => JWK,
verify_claims => VerifyClaims}};
@ -229,6 +229,16 @@ create2(#{use_jwks := true,
{error, Reason}
end.
create_jwk_from_pem_or_file(CertfileOrFilePath)
when is_binary(CertfileOrFilePath);
is_list(CertfileOrFilePath) ->
case filelib:is_file(CertfileOrFilePath) of
true ->
jose_jwk:from_pem_file(CertfileOrFilePath);
false ->
jose_jwk:from_pem(iolist_to_binary(CertfileOrFilePath))
end.
connector_opts(#{ssl := #{enable := Enable} = SSL} = Config) ->
SSLOpts = case Enable of
true -> maps:without([enable], SSL);