@@ -63,7 +63,6 @@ def transform_json(self, data: dict[str, Any], request: Request) -> dict[str, An
63
63
if self .extension_url not in extensions :
64
64
extensions .append (self .extension_url )
65
65
66
- # TODO: Should we add this to items even if the assets don't match the asset expression?
67
66
# auth:schemes
68
67
# ---
69
68
# A property that contains all of the scheme definitions used by Assets and
@@ -72,18 +71,28 @@ def transform_json(self, data: dict[str, Any], request: Request) -> dict[str, An
72
71
# - Collections
73
72
# - Item Properties
74
73
75
- if self .state_key not in request .state :
74
+ oidc_metadata = getattr (request .state , self .state_key , {})
75
+ if not oidc_metadata :
76
76
logger .error (
77
- "OIDC metadata not found in scope. "
78
- "Skipping authentication extension."
77
+ "OIDC metadata not found in scope. Skipping authentication extension."
79
78
)
80
79
return data
81
80
82
81
scheme_loc = data ["properties" ] if "properties" in data else data
83
82
schemes = scheme_loc .setdefault ("auth:schemes" , {})
84
- schemes [self .auth_scheme_name ] = self .parse_oidc_config (
85
- request .state .get (self .state_key , {})
86
- )
83
+ schemes [self .auth_scheme_name ] = {
84
+ "type" : "oauth2" ,
85
+ "description" : "requires an authentication token" ,
86
+ "flows" : {
87
+ "authorizationCode" : {
88
+ "authorizationUrl" : oidc_metadata ["authorization_endpoint" ],
89
+ "tokenUrl" : oidc_metadata .get ("token_endpoint" ),
90
+ "scopes" : {
91
+ k : k for k in sorted (oidc_metadata .get ("scopes_supported" , []))
92
+ },
93
+ },
94
+ },
95
+ }
87
96
88
97
# auth:refs
89
98
# ---
@@ -114,19 +123,3 @@ def transform_json(self, data: dict[str, Any], request: Request) -> dict[str, An
114
123
link .setdefault ("auth:refs" , []).append (self .auth_scheme_name )
115
124
116
125
return data
117
-
118
- def parse_oidc_config (self , oidc_config : dict [str , Any ]) -> dict [str , Any ]:
119
- """Parse the OIDC configuration."""
120
- return {
121
- "type" : "oauth2" ,
122
- "description" : "requires an authentication token" ,
123
- "flows" : {
124
- "authorizationCode" : {
125
- "authorizationUrl" : oidc_config ["authorization_endpoint" ],
126
- "tokenUrl" : oidc_config .get ("token_endpoint" ),
127
- "scopes" : {
128
- k : k for k in sorted (oidc_config .get ("scopes_supported" , []))
129
- },
130
- },
131
- },
132
- }
0 commit comments