Przeglądaj źródła

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

fix(authn-jwt): accept the pem conntet to create jwk authenticator
JianBo He 3 lat temu
rodzic
commit
85d1a4f9bf
1 zmienionych plików z 11 dodań i 1 usunięć
  1. 11 1
      apps/emqx_authn/src/simple_authn/emqx_authn_jwt.erl

+ 11 - 1
apps/emqx_authn/src/simple_authn/emqx_authn_jwt.erl

@@ -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);