fix(authn-jwt): accept the pem conntet to create jwk authenticator

This commit is contained in:
JianBo He 2022-03-10 13:30:25 +08:00
parent 34764a5c8e
commit 333f170a30
1 changed files with 11 additions and 1 deletions

View File

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