1212 translate_oauth_providers /1 ,
1313 translate_resource_servers /1 ,
1414 translate_signing_keys /1 ,
15- translate_endpoint_params /2
15+ translate_endpoint_params /2 ,
16+ translate_scope_aliases /1
1617]).
1718
1819extract_key_as_binary ({Name ,_ }) -> list_to_binary (Name ).
1920extract_value ({_Name ,V }) -> V .
2021
22+ -spec translate_scope_aliases ([{list (), binary ()}]) -> map ().
23+ translate_scope_aliases (Conf ) ->
24+ Settings = cuttlefish_variable :filter_by_prefix (" auth_oauth2.scope_aliases" , Conf ),
25+ maps :merge (extract_scope_aliases_as_a_map (Settings ),
26+ extract_scope_aliases_as_a_list_of_alias_scope_props (Settings )).
27+
28+ convert_space_separated_string_to_list_of_binaries (String ) ->
29+ [ list_to_binary (V ) || V <- string :tokens (String , " " )].
30+
31+ extract_scope_aliases_as_a_map (Settings ) ->
32+ maps :from_list ([{
33+ list_to_binary (K ),
34+ convert_space_separated_string_to_list_of_binaries (V )
35+ } || {[" auth_oauth2" , " scope_aliases" , K ], V } <- Settings ]).
36+ extract_scope_aliases_as_a_list_of_alias_scope_props (Settings ) ->
37+ KeyFun = fun extract_key_as_binary /1 ,
38+ ValueFun = fun extract_value /1 ,
39+
40+ List0 = [{K , {list_to_atom (Attr ), list_to_binary (V )}}
41+ || {[" auth_oauth2" , " scope_aliases" , K , Attr ], V } <- Settings ],
42+ List1 = maps :to_list (maps :groups_from_list (KeyFun , ValueFun , List0 )),
43+ maps :from_list ([
44+ extract_scope_alias_mapping (Proplist ) || {_ , Proplist } <- List1 ]).
45+
46+ extract_scope_alias_mapping (Proplist ) ->
47+ Alias =
48+ case proplists :get_value (alias , Proplist ) of
49+ undefined -> {error , missing_alias_attribute };
50+ A -> A
51+ end ,
52+ Scope =
53+ case proplists :get_value (scope , Proplist ) of
54+ undefined -> {error , missing_scope_attribute };
55+ S -> convert_space_separated_string_to_list_of_binaries (S )
56+ end ,
57+ case {Alias , Scope } of
58+ {{error , _ } = Err0 , _ } -> Err0 ;
59+ {_ , {error , _ } = Err1 } -> Err1 ;
60+ _ = V -> V
61+ end .
62+
2163-spec translate_resource_servers ([{list (), binary ()}]) -> map ().
2264translate_resource_servers (Conf ) ->
2365 Settings = cuttlefish_variable :filter_by_prefix (" auth_oauth2.resource_servers" ,
@@ -134,7 +176,7 @@ extract_resource_server_properties(Settings) ->
134176 ValueFun = fun extract_value /1 ,
135177
136178 OAuthProviders = [{Name , {list_to_atom (Key ), list_to_binary (V )}}
137- || {[" auth_oauth2" ," resource_servers" , Name , Key ], V } <- Settings ],
179+ || {[" auth_oauth2" , " resource_servers" , Name , Key ], V } <- Settings ],
138180 maps :groups_from_list (KeyFun , ValueFun , OAuthProviders ).
139181
140182mapOauthProviderProperty ({Key , Value }) ->
@@ -156,7 +198,7 @@ extract_oauth_providers_https(Settings) ->
156198 ExtractProviderNameFun = fun extract_key_as_binary /1 ,
157199
158200 AttributesPerProvider = [{Name , mapHttpProperty ({list_to_atom (Key ), V })} ||
159- {[" auth_oauth2" ," oauth_providers" , Name , " https" , Key ], V } <- Settings ],
201+ {[" auth_oauth2" , " oauth_providers" , Name , " https" , Key ], V } <- Settings ],
160202
161203 maps :map (fun (_K ,V )-> [{https , V }] end ,
162204 maps :groups_from_list (ExtractProviderNameFun , fun ({_ , V }) -> V end ,
0 commit comments