|
|
@@ -43,36 +43,57 @@
|
|
|
%% Hocon Schema
|
|
|
%%------------------------------------------------------------------------------
|
|
|
|
|
|
-namespace() -> "authn-jwt".
|
|
|
+namespace() -> "authn".
|
|
|
|
|
|
tags() ->
|
|
|
[<<"Authentication">>].
|
|
|
|
|
|
+%% used for config check when the schema module is resolved
|
|
|
roots() ->
|
|
|
[
|
|
|
{?CONF_NS,
|
|
|
hoconsc:mk(
|
|
|
- hoconsc:union(fun union_member_selector/1),
|
|
|
+ hoconsc:union(fun ?MODULE:union_member_selector/1),
|
|
|
#{}
|
|
|
)}
|
|
|
].
|
|
|
|
|
|
-fields('hmac-based') ->
|
|
|
+fields(jwt_hmac) ->
|
|
|
[
|
|
|
- {use_jwks, sc(hoconsc:enum([false]), #{required => true, desc => ?DESC(use_jwks)})},
|
|
|
+ %% for hmac, it's the 'algorithm' field which selects this type
|
|
|
+ %% use_jwks field can be ignored (kept for backward compatibility)
|
|
|
+ {use_jwks,
|
|
|
+ sc(
|
|
|
+ hoconsc:enum([false]),
|
|
|
+ #{
|
|
|
+ required => false,
|
|
|
+ desc => ?DESC(use_jwks),
|
|
|
+ importance => ?IMPORTANCE_HIDDEN
|
|
|
+ }
|
|
|
+ )},
|
|
|
{algorithm,
|
|
|
sc(hoconsc:enum(['hmac-based']), #{required => true, desc => ?DESC(algorithm)})},
|
|
|
{secret, fun secret/1},
|
|
|
{secret_base64_encoded, fun secret_base64_encoded/1}
|
|
|
] ++ common_fields();
|
|
|
-fields('public-key') ->
|
|
|
+fields(jwt_public_key) ->
|
|
|
[
|
|
|
- {use_jwks, sc(hoconsc:enum([false]), #{required => true, desc => ?DESC(use_jwks)})},
|
|
|
+ %% for public-key, it's the 'algorithm' field which selects this type
|
|
|
+ %% use_jwks field can be ignored (kept for backward compatibility)
|
|
|
+ {use_jwks,
|
|
|
+ sc(
|
|
|
+ hoconsc:enum([false]),
|
|
|
+ #{
|
|
|
+ required => false,
|
|
|
+ desc => ?DESC(use_jwks),
|
|
|
+ importance => ?IMPORTANCE_HIDDEN
|
|
|
+ }
|
|
|
+ )},
|
|
|
{algorithm,
|
|
|
sc(hoconsc:enum(['public-key']), #{required => true, desc => ?DESC(algorithm)})},
|
|
|
{public_key, fun public_key/1}
|
|
|
] ++ common_fields();
|
|
|
-fields('jwks') ->
|
|
|
+fields(jwt_jwks) ->
|
|
|
[
|
|
|
{use_jwks, sc(hoconsc:enum([true]), #{required => true, desc => ?DESC(use_jwks)})},
|
|
|
{endpoint, fun endpoint/1},
|
|
|
@@ -85,12 +106,12 @@ fields('jwks') ->
|
|
|
}}
|
|
|
] ++ common_fields().
|
|
|
|
|
|
-desc('hmac-based') ->
|
|
|
- ?DESC('hmac-based');
|
|
|
-desc('public-key') ->
|
|
|
- ?DESC('public-key');
|
|
|
-desc('jwks') ->
|
|
|
- ?DESC('jwks');
|
|
|
+desc(jwt_hmac) ->
|
|
|
+ ?DESC(jwt_hmac);
|
|
|
+desc(jwt_public_key) ->
|
|
|
+ ?DESC(jwt_public_key);
|
|
|
+desc(jwt_jwks) ->
|
|
|
+ ?DESC(jwt_jwks);
|
|
|
desc(undefined) ->
|
|
|
undefined.
|
|
|
|
|
|
@@ -160,9 +181,9 @@ from(_) -> undefined.
|
|
|
|
|
|
refs() ->
|
|
|
[
|
|
|
- hoconsc:ref(?MODULE, 'hmac-based'),
|
|
|
- hoconsc:ref(?MODULE, 'public-key'),
|
|
|
- hoconsc:ref(?MODULE, 'jwks')
|
|
|
+ hoconsc:ref(?MODULE, jwt_hmac),
|
|
|
+ hoconsc:ref(?MODULE, jwt_public_key),
|
|
|
+ hoconsc:ref(?MODULE, jwt_jwks)
|
|
|
].
|
|
|
|
|
|
union_member_selector(all_union_members) ->
|
|
|
@@ -181,9 +202,9 @@ boolean(Other) -> Other.
|
|
|
select_ref(true, _) ->
|
|
|
[hoconsc:ref(?MODULE, 'jwks')];
|
|
|
select_ref(false, #{<<"public_key">> := _}) ->
|
|
|
- [hoconsc:ref(?MODULE, 'public-key')];
|
|
|
+ [hoconsc:ref(?MODULE, jwt_public_key)];
|
|
|
select_ref(false, _) ->
|
|
|
- [hoconsc:ref(?MODULE, 'hmac-based')];
|
|
|
+ [hoconsc:ref(?MODULE, jwt_hmac)];
|
|
|
select_ref(_, _) ->
|
|
|
throw(#{
|
|
|
field_name => use_jwks,
|