blib/lib/Lemonldap/NG/Common/OpenIDConnect/Metadata.pm untested

filter: Statementstmt 0.0% 0 / 67 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 117 CC 11 SCAR 45.8
CC
11
Cov
0%
metadataDoc
132.0
BEGIN
2.0
BEGIN
2.0
CRAP 97.3
1 package Lemonldap::NG::Common::OpenIDConnect::Metadata;
2  
3 use strict;
4 use Lemonldap::NG::Common::OpenIDConnect::Constants;
5 use JSON;
6 use Mouse::Role;
7  
8 our $VERSION = '2.22.0';
9  
10 sub metadataDoc {
11 my ( $self, $issuer, $conf, $path ) = @_;
12 $conf //= $self->conf;
13 my $issuerDBOpenIDConnectPath = $conf->{issuerDBOpenIDConnectPath};
14 my $authorize_uri = $conf->{oidcServiceMetaDataAuthorizeURI};
15 my $token_uri = $conf->{oidcServiceMetaDataTokenURI};
16 my $userinfo_uri = $conf->{oidcServiceMetaDataUserInfoURI};
17 my $jwks_uri = $conf->{oidcServiceMetaDataJWKSURI};
18 my $registration_uri = $conf->{oidcServiceMetaDataRegistrationURI};
19 my $endsession_uri = $conf->{oidcServiceMetaDataEndSessionURI};
20 my $checksession_uri = $conf->{oidcServiceMetaDataCheckSessionURI};
21 my $disallowNoneAlg = $conf->{oidcServiceMetaDataDisallowNoneAlg};
22 my $introspection_uri = $conf->{oidcServiceMetaDataIntrospectionURI};
23 my $revoke_uri = $conf->{oidcServiceMetaDataRevokeURI};
24  
25 $path ||= $self->path . '/';
26 $path = "/" . $path unless ( $issuer =~ /\/$/ );
27 my $baseUrl = $issuer . $path;
28  
29 my @acr = keys %{ $conf->{oidcServiceMetaDataAuthnContext} };
30  
31 # List response types depending on allowed flows
32 my $response_types = [];
33 my $grant_types = [];
34 if ( $conf->{oidcServiceAllowAuthorizationCodeFlow} ) {
35 push( @$response_types, "code" );
36 push( @$grant_types, "authorization_code" );
37 }
38 if ( $conf->{oidcServiceAllowImplicitFlow} ) {
39 push( @$response_types, "id_token", "id_token token" );
40 push( @$grant_types, "implicit" );
41 }
42  
43 # If one of the RPs has password grant enabled
44 if (
45 grep {
46 $conf->{oidcRPMetaDataOptions}->{$_}
47 ->{oidcRPMetaDataOptionsAllowPasswordGrant}
48 } keys %{ $conf->{oidcRPMetaDataOptions} // {} }
49 )
50 {
51 push( @$grant_types, "password" );
52 }
53  
54 # If one of the RPs has client credentials grant enabled
55 if (
56 grep {
57 $conf->{oidcRPMetaDataOptions}->{$_}
58 ->{oidcRPMetaDataOptionsAllowClientCredentialsGrant}
59 } keys %{ $conf->{oidcRPMetaDataOptions} // {} }
60 )
61 {
62 push( @$grant_types, "client_credentials" );
63 }
64  
65 # If one of the RPs has refresh tokens enabled
66 if (
67 grep {
68 $conf->{oidcRPMetaDataOptions}->{$_}
69 ->{oidcRPMetaDataOptionsRefreshToken}
70 or $conf->{oidcRPMetaDataOptions}->{$_}
71 ->{oidcRPMetaDataOptionsAllowOffline}
72 }
73 keys %{ $conf->{oidcRPMetaDataOptions} // {} }
74 )
75 {
76 push( @$grant_types, "refresh_token" );
77 }
78  
79 if ( $conf->{oidcServiceAllowHybridFlow} ) {
80 push( @$response_types,
81 "code id_token",
82 "code token", "code id_token token" );
83 push( @$grant_types, "hybrid" );
84 }
85  
86 my @supportedSigAlg = qw/HS256 HS384 HS512/;
87 unshift @supportedSigAlg, 'none' unless $disallowNoneAlg;
88 if ( $conf->{oidcServiceKeyTypeSig} eq 'EC' ) {
89 push @supportedSigAlg, qw/ES256 ES256K ES384 ES512 EdDSA/;
90 }
91 else {
92 push @supportedSigAlg, qw/RS256 RS384 RS512 PS256 PS384 PS512/;
93 }
94  
95 # Create OpenID configuration hash;
96 return {
97 issuer => $issuer,
98  
99 # Endpoints
100 authorization_endpoint => $baseUrl . $authorize_uri,
101 token_endpoint => $baseUrl . $token_uri,
102 userinfo_endpoint => $baseUrl . $userinfo_uri,
103 jwks_uri => $baseUrl . $jwks_uri,
104 (
105 $conf->{oidcServiceAllowDynamicRegistration}
106 ? ( registration_endpoint => $baseUrl . $registration_uri )
107 : ()
108 ),
109 end_session_endpoint => $baseUrl . $endsession_uri,
110  
111 #check_session_iframe => $baseUrl . $checksession_uri,
112 introspection_endpoint => $baseUrl . $introspection_uri,
113 revocation_endpoint => $baseUrl . $revoke_uri,
114  
115 # Scopes
116 scopes_supported => [qw/openid profile email address phone/],
117 response_types_supported => $response_types,
118 response_modes_supported => [ "query", "fragment", "form_post", ],
119 grant_types_supported => $grant_types,
120 acr_values_supported => \@acr,
121 subject_types_supported => ["public"],
122 token_endpoint_auth_methods_supported =>
123 [qw/client_secret_post client_secret_basic/],
124 introspection_endpoint_auth_methods_supported =>
125 [qw/client_secret_post client_secret_basic/],
126 claims_supported => [qw/sub iss auth_time acr sid/],
127 request_parameter_supported => JSON::true,
128 request_uri_parameter_supported => JSON::true,
129 require_request_uri_registration => JSON::true,
130  
131 # Algorithms
132 id_token_signing_alg_values_supported => \@supportedSigAlg,
133  
134 id_token_encryption_alg_values_supported => ENC_ALG_SUPPORTED,
135 id_token_encryption_enc_values_supported => ENC_SUPPORTED,
136 userinfo_signing_alg_values_supported => \@supportedSigAlg,
137  
138 userinfo_encryption_alg_values_supported => ENC_ALG_SUPPORTED,
139 userinfo_encryption_enc_values_supported => ENC_SUPPORTED,
140  
141 # Introspection response (RFC 9701)
142 introspection_signing_alg_values_supported => \@supportedSigAlg,
143 introspection_encryption_alg_values_supported => ENC_ALG_SUPPORTED,
144 introspection_encryption_enc_values_supported => ENC_SUPPORTED,
145  
146 # PKCE
147 code_challenge_methods_supported => [qw/plain S256/],
148  
149 # Logout supported methods
150 frontchannel_logout_supported => JSON::true,
151 frontchannel_logout_session_supported => JSON::true,
152 backchannel_logout_supported => JSON::true,
153 backchannel_logout_session_supported => JSON::true,
154  
155 # request_object_signing_alg_values_supported
156 # request_object_encryption_alg_values_supported
157 # request_object_encryption_enc_values_supported
158  
159 # token_endpoint_auth_signing_alg_values_supported
160 # display_values_supported
161 # claim_types_supported
162 # service_documentation
163 # claims_locales_supported
164 # ui_locales_supported
165 # claims_parameter_supported
166  
167 # op_policy_uri
168 # op_tos_uri
169 };
170 }
171  
172 1;