diff options
author | Vivien Kraus <vivien@planete-kraus.eu> | 2021-10-14 14:23:51 +0200 |
---|---|---|
committer | Vivien Kraus <vivien@planete-kraus.eu> | 2021-10-19 11:32:00 +0200 |
commit | a219bf64933d3313aebe0e5576b291e32e93d93f (patch) | |
tree | cac1226f500dfbd5a7daf991bfc2b157846ad83d | |
parent | 19915a8b5b2912d255a6850a5d8d796a4f9c7fc9 (diff) |
server: add an exception for showing a message to the user
-rw-r--r-- | doc/disfluid.texi | 70 | ||||
-rw-r--r-- | po/disfluid.pot | 102 | ||||
-rw-r--r-- | po/fr.po | 125 | ||||
-rw-r--r-- | src/scm/webid-oidc/client-manifest.scm | 47 | ||||
-rw-r--r-- | src/scm/webid-oidc/errors.scm | 15 | ||||
-rw-r--r-- | src/scm/webid-oidc/server/endpoint.scm | 64 | ||||
-rw-r--r-- | src/scm/webid-oidc/token-endpoint.scm | 21 |
7 files changed, 289 insertions, 155 deletions
diff --git a/doc/disfluid.texi b/doc/disfluid.texi index fa5347a..6b9ad08 100644 --- a/doc/disfluid.texi +++ b/doc/disfluid.texi @@ -1539,10 +1539,80 @@ Return the path prefix @var{endpoint} is configured to respond to. Check if @var{endpoint} is configured to respond to @var{request}. @end deffn +The handler may throw exceptions to signal errors. Exception messages +will be printed to the log file, and user messages will be passed to +the user. + @menu +* Error signalling:: * Router endpoint:: @end menu +@node Error signalling +@section Error signalling +The @emph{(webid-oidc server endpoint)} module defines exception types +that can be emitted to abort the computation in a handler. If an +exception of a different kind is raised, this will lead to a 500 +Internal Server Error response. + +@deftp {Exception type} &web-exception @var{code} @var{reason-phrase} +The request failed, with @var{code} and @var{reason-phrase}. +@end deftp + +@deffn {function} make-web-exception @var{code} @var{reason-phrase} +Create an exception with @var{code} and @var{reason-phrase}. +@end deffn + +@deffn {function} web-exception? @var{exn} +Check if @var{exn} was thrown because the request failed. +@end deffn + +@deffn {function} web-exception-code @var{exn} +@deffnx {function} web-exception-reason-phrase @var{exn} +Return the code and reason-phrase for when @var{exn} was thrown, if it +was thrown because of a failing request. +@end deffn + +@deftp {Exception type} &caused-by-user @var{webid} +If a web exception is raised, maybe it is caused by some user +identified by @var{webid} (an URI, or @code{#f}. +@end deftp + +@deffn {function} make-caused-by-user @var{webid} +Constructor for @code{&caused-by-user}. +@end deffn + +@deffn {function} caused-by-user? @var{exn} +Check if @var{exn} was caused by the user. +@end deffn + +@deffn {function} caused-by-user-webid @var{exn} +Return the webid of the user that caused @var{exn}. +@end deffn + +@deftp {Exception type} &user-message @var{sxml} +An exception containing a message that is safe to show to the user, as +an SXML fragment of XHTML. Typically, this would be a @code{<p/>}, or +a @code{<div/>}. + +You can set a user-message multiple times. The occurences will be +concatenated in the response, in the order they appear in the +composite exception. +@end deftp + +@deffn {function} make-user-message @var{sxml} +Create a new user message containing the @var{sxml} fragment. +@end deffn + +@deffn {function} user-message? @var{exn} +Check if there is at least one user message in @var{exn}. +@end deffn + +@deffn {function} user-message-sxml @var{exn} +Return all user messages in @var{exn}, as a @code{<div/>} SXML +fragment. +@end deffn + @node Router endpoint @section Router endpoint The first non-trivial handler is for the router endpoint, defined in diff --git a/po/disfluid.pot b/po/disfluid.pot index 6468cb0..c4468f3 100644 --- a/po/disfluid.pot +++ b/po/disfluid.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: disfluid SNAPSHOT\n" "Report-Msgid-Bugs-To: vivien@planete-kraus.eu\n" -"POT-Creation-Date: 2021-10-19 11:29+0200\n" +"POT-Creation-Date: 2021-10-19 11:31+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" @@ -238,7 +238,7 @@ msgid "#:webid should be an URI" msgstr "" #: src/scm/webid-oidc/access-token.scm:122 -#: src/scm/webid-oidc/client-manifest.scm:212 +#: src/scm/webid-oidc/client-manifest.scm:223 msgid "#:client-id should be an URI" msgstr "" @@ -282,9 +282,9 @@ msgstr "" #: src/scm/webid-oidc/hello-world.scm:167 #: src/scm/webid-oidc/hello-world.scm:187 #: src/scm/webid-oidc/identity-provider.scm:136 -#: src/scm/webid-oidc/token-endpoint.scm:112 -#: src/scm/webid-oidc/token-endpoint.scm:138 -#: src/scm/webid-oidc/token-endpoint.scm:165 +#: src/scm/webid-oidc/token-endpoint.scm:113 +#: src/scm/webid-oidc/token-endpoint.scm:139 +#: src/scm/webid-oidc/token-endpoint.scm:166 msgid "xml-lang|en" msgstr "" @@ -319,8 +319,8 @@ msgid "Allow" msgstr "" #: src/scm/webid-oidc/authorization-page-unsafe.scm:95 -#: src/scm/webid-oidc/token-endpoint.scm:130 -#: src/scm/webid-oidc/token-endpoint.scm:157 +#: src/scm/webid-oidc/token-endpoint.scm:131 +#: src/scm/webid-oidc/token-endpoint.scm:158 msgid "reason-phrase|Bad Request" msgstr "" @@ -394,76 +394,76 @@ msgstr "" msgid "Unsupported delegate catalog URI scheme: ~s\n" msgstr "" -#: src/scm/webid-oidc/client-manifest.scm:143 +#: src/scm/webid-oidc/client-manifest.scm:144 #, scheme-format msgid "cannot fetch a client manifest: ~a" msgstr "" -#: src/scm/webid-oidc/client-manifest.scm:145 +#: src/scm/webid-oidc/client-manifest.scm:146 msgid "cannot fetch a client manifest" msgstr "" -#: src/scm/webid-oidc/client-manifest.scm:154 +#: src/scm/webid-oidc/client-manifest.scm:155 #, scheme-format msgid "the server responded with code ~a" msgstr "" -#: src/scm/webid-oidc/client-manifest.scm:157 +#: src/scm/webid-oidc/client-manifest.scm:159 #, scheme-format -msgid "The server hosting your application responded with code ~a." +msgid "<p>The server hosting your application responded with code ~a.<p>" msgstr "" -#: src/scm/webid-oidc/client-manifest.scm:166 -#: src/scm/webid-oidc/client-manifest.scm:195 +#: src/scm/webid-oidc/client-manifest.scm:169 +#: src/scm/webid-oidc/client-manifest.scm:202 msgid "the client manifest does not have a client_id field" msgstr "" -#: src/scm/webid-oidc/client-manifest.scm:168 -#: src/scm/webid-oidc/client-manifest.scm:197 +#: src/scm/webid-oidc/client-manifest.scm:172 +#: src/scm/webid-oidc/client-manifest.scm:205 msgid "" -"The server hosting your application does not behave correctly, because it " -"lacks the client_id field." +"<p>The server hosting your application does not behave correctly, because it " +"lacks the client_id field.<p>" msgstr "" -#: src/scm/webid-oidc/client-manifest.scm:188 +#: src/scm/webid-oidc/client-manifest.scm:193 msgid "the client manifest does not have a redirect_uris field" msgstr "" -#: src/scm/webid-oidc/client-manifest.scm:190 +#: src/scm/webid-oidc/client-manifest.scm:196 msgid "" -"The server hosting your application does not behave correctly, because it " -"lacks the redirect_uris field." +"<p>The server hosting your application does not behave correctly, because it " +"lacks the redirect_uris field.<p>" msgstr "" -#: src/scm/webid-oidc/client-manifest.scm:203 +#: src/scm/webid-oidc/client-manifest.scm:212 #, scheme-format msgid "the client manifest under ~s has a client_id of ~s" msgstr "" -#: src/scm/webid-oidc/client-manifest.scm:207 +#: src/scm/webid-oidc/client-manifest.scm:217 msgid "" -"The application you want to use does not control the domain name it appears " -"to represent." +"<p>The application you want to use does not control the domain name it " +"appears to represent.</p>" msgstr "" -#: src/scm/webid-oidc/client-manifest.scm:221 +#: src/scm/webid-oidc/client-manifest.scm:232 msgid "#:redirect-uris should be a list of URIs" msgstr "" -#: src/scm/webid-oidc/client-manifest.scm:231 +#: src/scm/webid-oidc/client-manifest.scm:242 #, scheme-format msgid "the client manifest does not allow ~s as a redirection uri" msgstr "" -#: src/scm/webid-oidc/client-manifest.scm:235 +#: src/scm/webid-oidc/client-manifest.scm:246 #, scheme-format msgid "" "<p>The application wants to get your\n" -"authorization through <strong>~s</strong>, which is not\n" +"authorization through <strong>~a</strong>, which is not\n" "approved.</p>" msgstr "" -#: src/scm/webid-oidc/client-manifest.scm:270 +#: src/scm/webid-oidc/client-manifest.scm:283 msgid "cannot serve the public manifest" msgstr "" @@ -2168,7 +2168,7 @@ msgid "~a: ignoring a group that cannot be fetched\n" msgstr "" #: src/scm/webid-oidc/resource-server.scm:334 -#: src/scm/webid-oidc/token-endpoint.scm:104 +#: src/scm/webid-oidc/token-endpoint.scm:105 msgid "reason-phrase|Forbidden" msgstr "" @@ -2222,27 +2222,35 @@ msgstr "" msgid "cannot POST to an auxiliary resource path, ~s" msgstr "" -#: src/scm/webid-oidc/server/endpoint.scm:65 +#: src/scm/webid-oidc/server/endpoint.scm:98 +msgid "No information available." +msgstr "" + +#: src/scm/webid-oidc/server/endpoint.scm:119 msgid "#:host should be a string or #f" msgstr "" -#: src/scm/webid-oidc/server/endpoint.scm:70 +#: src/scm/webid-oidc/server/endpoint.scm:124 msgid "#:path should be an absolute path" msgstr "" -#: src/scm/webid-oidc/server/endpoint.scm:90 +#: src/scm/webid-oidc/server/endpoint.scm:144 #, scheme-format msgid "#:routed element ~a should be an endpoint" msgstr "" -#: src/scm/webid-oidc/server/endpoint.scm:95 +#: src/scm/webid-oidc/server/endpoint.scm:149 msgid "#:routed should be a list of endpoints" msgstr "" -#: src/scm/webid-oidc/server/endpoint.scm:128 src/ui/error-page.glade:73 +#: src/scm/webid-oidc/server/endpoint.scm:181 src/ui/error-page.glade:73 msgid "Not Found" msgstr "" +#: src/scm/webid-oidc/server/endpoint.scm:182 +msgid "The resource could not be found." +msgstr "" + #: src/scm/webid-oidc/server/read.scm:101 #, scheme-format msgid "the auxiliary resource of type ~s at ~s is absent" @@ -2296,46 +2304,46 @@ msgstr "" msgid "an error happened while updating file ~s" msgstr "" -#: src/scm/webid-oidc/token-endpoint.scm:92 +#: src/scm/webid-oidc/token-endpoint.scm:93 #, scheme-format msgid "while handling web failure for the token endpoint: ~a" msgstr "" -#: src/scm/webid-oidc/token-endpoint.scm:94 +#: src/scm/webid-oidc/token-endpoint.scm:95 msgid "an error happened during the token endpoint failure handling" msgstr "" -#: src/scm/webid-oidc/token-endpoint.scm:224 +#: src/scm/webid-oidc/token-endpoint.scm:225 msgid "missing grant type" msgstr "" -#: src/scm/webid-oidc/token-endpoint.scm:228 +#: src/scm/webid-oidc/token-endpoint.scm:229 msgid "<p>You did not specify a grant_type for this request.</p>" msgstr "" -#: src/scm/webid-oidc/token-endpoint.scm:242 +#: src/scm/webid-oidc/token-endpoint.scm:243 msgid "missing authorization code" msgstr "" -#: src/scm/webid-oidc/token-endpoint.scm:246 +#: src/scm/webid-oidc/token-endpoint.scm:247 msgid "" "<p>You want to grant an authorization code, but you did not set one.</p>" msgstr "" -#: src/scm/webid-oidc/token-endpoint.scm:267 +#: src/scm/webid-oidc/token-endpoint.scm:268 msgid "missing refresh token" msgstr "" -#: src/scm/webid-oidc/token-endpoint.scm:271 +#: src/scm/webid-oidc/token-endpoint.scm:272 msgid "<p>You want to grant a refresh token, but you did not set one.</p>" msgstr "" -#: src/scm/webid-oidc/token-endpoint.scm:284 +#: src/scm/webid-oidc/token-endpoint.scm:285 #, scheme-format msgid "unsupported grant type: ~s" msgstr "" -#: src/scm/webid-oidc/token-endpoint.scm:289 +#: src/scm/webid-oidc/token-endpoint.scm:290 #, scheme-format msgid "" "<p>You want to use <pre>~s</pre> as a grant type, but this is not supported." @@ -2,8 +2,8 @@ msgid "" msgstr "" "Project-Id-Version: webid-oidc 0.0.0\n" "Report-Msgid-Bugs-To: vivien@planete-kraus.eu\n" -"POT-Creation-Date: 2021-10-19 11:29+0200\n" -"PO-Revision-Date: 2021-10-18 13:25+0200\n" +"POT-Creation-Date: 2021-10-19 11:31+0200\n" +"PO-Revision-Date: 2021-10-19 11:31+0200\n" "Last-Translator: Vivien Kraus <vivien@planete-kraus.eu>\n" "Language-Team: French <vivien@planete-kraus.eu>\n" "Language: fr\n" @@ -264,7 +264,7 @@ msgid "#:webid should be an URI" msgstr "#:webid doit être une URI" #: src/scm/webid-oidc/access-token.scm:122 -#: src/scm/webid-oidc/client-manifest.scm:212 +#: src/scm/webid-oidc/client-manifest.scm:223 msgid "#:client-id should be an URI" msgstr "#:client-id doit être une URI" @@ -313,9 +313,9 @@ msgstr "" #: src/scm/webid-oidc/hello-world.scm:167 #: src/scm/webid-oidc/hello-world.scm:187 #: src/scm/webid-oidc/identity-provider.scm:136 -#: src/scm/webid-oidc/token-endpoint.scm:112 -#: src/scm/webid-oidc/token-endpoint.scm:138 -#: src/scm/webid-oidc/token-endpoint.scm:165 +#: src/scm/webid-oidc/token-endpoint.scm:113 +#: src/scm/webid-oidc/token-endpoint.scm:139 +#: src/scm/webid-oidc/token-endpoint.scm:166 msgid "xml-lang|en" msgstr "fr" @@ -350,8 +350,8 @@ msgid "Allow" msgstr "Autoriser" #: src/scm/webid-oidc/authorization-page-unsafe.scm:95 -#: src/scm/webid-oidc/token-endpoint.scm:130 -#: src/scm/webid-oidc/token-endpoint.scm:157 +#: src/scm/webid-oidc/token-endpoint.scm:131 +#: src/scm/webid-oidc/token-endpoint.scm:158 msgid "reason-phrase|Bad Request" msgstr "Requête Invalide" @@ -428,84 +428,85 @@ msgstr "URI relative invalide" msgid "Unsupported delegate catalog URI scheme: ~s\n" msgstr "Schéma d’URI pour un catalogue délégé non supporté : ~s\n" -#: src/scm/webid-oidc/client-manifest.scm:143 +#: src/scm/webid-oidc/client-manifest.scm:144 #, scheme-format msgid "cannot fetch a client manifest: ~a" msgstr "impossible de télécharger un manifeste client : ~a" -#: src/scm/webid-oidc/client-manifest.scm:145 +#: src/scm/webid-oidc/client-manifest.scm:146 msgid "cannot fetch a client manifest" msgstr "impossible de télécharger un manifeste client" -#: src/scm/webid-oidc/client-manifest.scm:154 +#: src/scm/webid-oidc/client-manifest.scm:155 #, scheme-format msgid "the server responded with code ~a" msgstr "le serveur a répondu avec le code ~a" -#: src/scm/webid-oidc/client-manifest.scm:157 +#: src/scm/webid-oidc/client-manifest.scm:159 #, scheme-format -msgid "The server hosting your application responded with code ~a." -msgstr "Le serveur hébergeant votre application a répondu avec le code ~a." +msgid "<p>The server hosting your application responded with code ~a.<p>" +msgstr "" +"<p>Le serveur hébergeant votre application a répondu avec le code ~a.</p>" -#: src/scm/webid-oidc/client-manifest.scm:166 -#: src/scm/webid-oidc/client-manifest.scm:195 +#: src/scm/webid-oidc/client-manifest.scm:169 +#: src/scm/webid-oidc/client-manifest.scm:202 msgid "the client manifest does not have a client_id field" msgstr "le manifeste client n’a pas de champ client_id" -#: src/scm/webid-oidc/client-manifest.scm:168 -#: src/scm/webid-oidc/client-manifest.scm:197 +#: src/scm/webid-oidc/client-manifest.scm:172 +#: src/scm/webid-oidc/client-manifest.scm:205 msgid "" -"The server hosting your application does not behave correctly, because it " -"lacks the client_id field." +"<p>The server hosting your application does not behave correctly, because it " +"lacks the client_id field.<p>" msgstr "" -"Le serveur hébergeant votre application ne se comporte pas correctement, " -"parce qu’il lui manque le champ client_id." +"<p>Le serveur hébergeant votre application ne se comporte pas correctement, " +"parce qu’il lui manque le champ client_id.</p>" -#: src/scm/webid-oidc/client-manifest.scm:188 +#: src/scm/webid-oidc/client-manifest.scm:193 msgid "the client manifest does not have a redirect_uris field" msgstr "le manifeste client n’a pas de champ redirect_uris" -#: src/scm/webid-oidc/client-manifest.scm:190 +#: src/scm/webid-oidc/client-manifest.scm:196 msgid "" -"The server hosting your application does not behave correctly, because it " -"lacks the redirect_uris field." +"<p>The server hosting your application does not behave correctly, because it " +"lacks the redirect_uris field.<p>" msgstr "" -"Le serveur hébergeant votre application ne se comporte pas correctement, " -"parce qu’il lui manque le champ redirect_uris." +"<p>Le serveur hébergeant votre application ne se comporte pas correctement, " +"parce qu’il lui manque le champ redirect_uris.</p>" -#: src/scm/webid-oidc/client-manifest.scm:203 +#: src/scm/webid-oidc/client-manifest.scm:212 #, scheme-format msgid "the client manifest under ~s has a client_id of ~s" msgstr "le manifeste client à ~s a un client_id valant ~s" -#: src/scm/webid-oidc/client-manifest.scm:207 +#: src/scm/webid-oidc/client-manifest.scm:217 msgid "" -"The application you want to use does not control the domain name it appears " -"to represent." +"<p>The application you want to use does not control the domain name it " +"appears to represent.</p>" msgstr "" -"L’application que vous voulez utiliser ne contrôle pas le nom de domaine " -"qu’elle prétend représenter." +"<p>L’application que vous voulez utiliser ne contrôle pas le nom de domaine " +"qu’elle prétend représenter.</p>" -#: src/scm/webid-oidc/client-manifest.scm:221 +#: src/scm/webid-oidc/client-manifest.scm:232 msgid "#:redirect-uris should be a list of URIs" msgstr "#:redirect-uris doit être une liste d’URIs" -#: src/scm/webid-oidc/client-manifest.scm:231 +#: src/scm/webid-oidc/client-manifest.scm:242 #, scheme-format msgid "the client manifest does not allow ~s as a redirection uri" msgstr "le manifeste client n’autorise pas ~s comme URI de redirection" -#: src/scm/webid-oidc/client-manifest.scm:235 +#: src/scm/webid-oidc/client-manifest.scm:246 #, scheme-format msgid "" "<p>The application wants to get your\n" -"authorization through <strong>~s</strong>, which is not\n" +"authorization through <strong>~a</strong>, which is not\n" "approved.</p>" msgstr "" -"<p>L’applicationn veut récupérer votre code d’autorisation via <strong>~s</" +"<p>L’applicationn veut récupérer votre code d’autorisation via <strong>~a</" "strong>, qui n’est pas approuvé.</p>" -#: src/scm/webid-oidc/client-manifest.scm:270 +#: src/scm/webid-oidc/client-manifest.scm:283 msgid "cannot serve the public manifest" msgstr "impossible de servir le manifeste public" @@ -2562,7 +2563,7 @@ msgid "~a: ignoring a group that cannot be fetched\n" msgstr "~a : j’ignore un groupe qui ne peut pas être téléchargé\n" #: src/scm/webid-oidc/resource-server.scm:334 -#: src/scm/webid-oidc/token-endpoint.scm:104 +#: src/scm/webid-oidc/token-endpoint.scm:105 msgid "reason-phrase|Forbidden" msgstr "Interdit" @@ -2618,27 +2619,35 @@ msgstr "la ressource créée ne peut pas avoir de triplets de contention" msgid "cannot POST to an auxiliary resource path, ~s" msgstr "impossible de POSTer vers un chemin de ressource auxiliaire, ~s" -#: src/scm/webid-oidc/server/endpoint.scm:65 +#: src/scm/webid-oidc/server/endpoint.scm:98 +msgid "No information available." +msgstr "Pas d’information disponible." + +#: src/scm/webid-oidc/server/endpoint.scm:119 msgid "#:host should be a string or #f" msgstr "#:host doit être une chaîne de caractères ou #f" -#: src/scm/webid-oidc/server/endpoint.scm:70 +#: src/scm/webid-oidc/server/endpoint.scm:124 msgid "#:path should be an absolute path" msgstr "#:path doit être un chemin URI absolu" -#: src/scm/webid-oidc/server/endpoint.scm:90 +#: src/scm/webid-oidc/server/endpoint.scm:144 #, scheme-format msgid "#:routed element ~a should be an endpoint" msgstr "élément #:routed ~a doit être un terminal" -#: src/scm/webid-oidc/server/endpoint.scm:95 +#: src/scm/webid-oidc/server/endpoint.scm:149 msgid "#:routed should be a list of endpoints" msgstr "#:routed doit être une liste de terminaux" -#: src/scm/webid-oidc/server/endpoint.scm:128 src/ui/error-page.glade:73 +#: src/scm/webid-oidc/server/endpoint.scm:181 src/ui/error-page.glade:73 msgid "Not Found" msgstr "Non Trouvé" +#: src/scm/webid-oidc/server/endpoint.scm:182 +msgid "The resource could not be found." +msgstr "La ressource n’a pas été trouvée." + #: src/scm/webid-oidc/server/read.scm:101 #, scheme-format msgid "the auxiliary resource of type ~s at ~s is absent" @@ -2692,51 +2701,51 @@ msgstr "pendant la mise à jour du fichier ~s : ~a" msgid "an error happened while updating file ~s" msgstr "une erreur est survenue pendant la mise à jour du fichier ~s" -#: src/scm/webid-oidc/token-endpoint.scm:92 +#: src/scm/webid-oidc/token-endpoint.scm:93 #, scheme-format msgid "while handling web failure for the token endpoint: ~a" msgstr "lors de la gestion d’un échec web pour le terminal de jeton : ~a" -#: src/scm/webid-oidc/token-endpoint.scm:94 +#: src/scm/webid-oidc/token-endpoint.scm:95 msgid "an error happened during the token endpoint failure handling" msgstr "" "une erreur est survenue pendant la gestion d’un échec du terminal de jeton" -#: src/scm/webid-oidc/token-endpoint.scm:224 +#: src/scm/webid-oidc/token-endpoint.scm:225 msgid "missing grant type" msgstr "type d’offre manquant" -#: src/scm/webid-oidc/token-endpoint.scm:228 +#: src/scm/webid-oidc/token-endpoint.scm:229 msgid "<p>You did not specify a grant_type for this request.</p>" msgstr "<p>Vous n’avez pas spécifié de grant_type pour cette requête.</p>" -#: src/scm/webid-oidc/token-endpoint.scm:242 +#: src/scm/webid-oidc/token-endpoint.scm:243 msgid "missing authorization code" msgstr "code d’autorisation manquant" -#: src/scm/webid-oidc/token-endpoint.scm:246 +#: src/scm/webid-oidc/token-endpoint.scm:247 msgid "" "<p>You want to grant an authorization code, but you did not set one.</p>" msgstr "" "<p>Vous voulez offrir un code d’autorisation, mais vous n’en avez pas défini." "</p>" -#: src/scm/webid-oidc/token-endpoint.scm:267 +#: src/scm/webid-oidc/token-endpoint.scm:268 msgid "missing refresh token" msgstr "jeton de rafraîchissement manquant" -#: src/scm/webid-oidc/token-endpoint.scm:271 +#: src/scm/webid-oidc/token-endpoint.scm:272 msgid "<p>You want to grant a refresh token, but you did not set one.</p>" msgstr "" "<p>Vous voulez offrir un jeton de rafraîchissement, mais vous n’en avez pas " "défini.</p>" -#: src/scm/webid-oidc/token-endpoint.scm:284 +#: src/scm/webid-oidc/token-endpoint.scm:285 #, scheme-format msgid "unsupported grant type: ~s" msgstr "type d’offre non supporté : ~s" -#: src/scm/webid-oidc/token-endpoint.scm:289 +#: src/scm/webid-oidc/token-endpoint.scm:290 #, scheme-format msgid "" "<p>You want to use <pre>~s</pre> as a grant type, but this is not supported." @@ -4559,10 +4568,6 @@ msgstr "Rejeter les modifications" #~ "--uri-sortant.\n" #, scheme-format -#~ msgid "the resource ~s could not be found (because ~a)" -#~ msgstr "la ressource ~s n’a pas été trouvée (parce que ~a)" - -#, scheme-format #~ msgid "the resource is missing an etag (see ~s)" #~ msgstr "la ressource n’a pas d’etag (voir ~s)" diff --git a/src/scm/webid-oidc/client-manifest.scm b/src/scm/webid-oidc/client-manifest.scm index 1d855c1..2d1f428 100644 --- a/src/scm/webid-oidc/client-manifest.scm +++ b/src/scm/webid-oidc/client-manifest.scm @@ -16,6 +16,7 @@ (define-module (webid-oidc client-manifest) #:use-module (webid-oidc errors) + #:use-module (webid-oidc server endpoint) #:use-module (webid-oidc fetch) #:use-module (webid-oidc web-i18n) #:use-module (webid-oidc serializable) @@ -153,9 +154,11 @@ (make-exception-with-message (format #f (G_ "the server responded with code ~a") (response-code response))) - (make-message-for-the-user - `(p ,(format #f (W_ "The server hosting your application responded with code ~a.") - (response-code response))))))) + (make-user-message + (call-with-input-string + (format #f (W_ "<p>The server hosting your application responded with code ~a.<p>") + (response-code response)) + xml->sxml))))) (let ((json-data (stubs:json-string->scm response-body))) (let ((new-client-id (assq-ref json-data 'client_id)) (redirect-uris (assq-ref json-data 'redirect_uris))) @@ -164,8 +167,10 @@ (make-exception (make-exception-with-message (G_ "the client manifest does not have a client_id field")) - (make-message-for-the-user - `(p ,(W_ "The server hosting your application does not behave correctly, because it lacks the client_id field.")))))) + (make-user-message + (call-with-input-string + (format #f (W_ "<p>The server hosting your application does not behave correctly, because it lacks the client_id field.<p>")) + xml->sxml))))) (set! redirect-uris (let fix-redirect-uris ((redirect-uris redirect-uris)) (match redirect-uris @@ -186,15 +191,19 @@ (make-exception (make-exception-with-message (G_ "the client manifest does not have a redirect_uris field")) - (make-message-for-the-user - `(p ,(W_ "The server hosting your application does not behave correctly, because it lacks the redirect_uris field.")))))) + (make-user-message + (call-with-input-string + (format #f (W_ "<p>The server hosting your application does not behave correctly, because it lacks the redirect_uris field.<p>")) + xml->sxml))))) (unless new-client-id (raise-exception (make-exception (make-exception-with-message (G_ "the client manifest does not have a client_id field")) - (make-message-for-the-user - `(p ,(W_ "The server hosting your application does not behave correctly, because it lacks the client_id field.")))))) + (make-user-message + (call-with-input-string + (format #f (W_ "<p>The server hosting your application does not behave correctly, because it lacks the client_id field.<p>")) + xml->sxml))))) (unless (equal? client-id new-client-id) (raise-exception (make-exception @@ -203,8 +212,10 @@ (format #f (G_ "the client manifest under ~s has a client_id of ~s") (uri->string client-id) (uri->string new-client-id))) - (make-message-for-the-user - `(p ,(W_ "The application you want to use does not control the domain name it appears to represent.")))))) + (make-user-message + (call-with-input-string + (format #f (W_ "<p>The application you want to use does not control the domain name it appears to represent.</p>")) + xml->sxml))))) (do-initialize new-client-id redirect-uris))))))) (else (unless (uri? client-id) @@ -231,16 +242,18 @@ (format #f (G_ "the client manifest does not allow ~s as a redirection uri") (uri->string redir))) (final-user-message - (sxml-match - (xml->sxml (W_ "<p>The application wants to get your -authorization through <strong>~s</strong>, which is not -approved.</p>")) - ((*TOP* ,element) element)))) + (call-with-input-string + (format #f (W_ "<p>The application wants to get your +authorization through <strong>~a</strong>, which is not +approved.</p>") + (call-with-output-string + (cute sxml->xml `(*TOP* ,(uri->string redir)) <>))) + xml->sxml))) (raise-exception (make-exception (make-unauthorized-redirect-uri) (make-exception-with-message final-message) - (make-message-for-the-user final-user-message))))) + (make-user-message final-user-message))))) (((? (cute equal? <> redir) redir) _ ...) #t) ((_ uris ...) diff --git a/src/scm/webid-oidc/errors.scm b/src/scm/webid-oidc/errors.scm index aabb6ea..6efc6c8 100644 --- a/src/scm/webid-oidc/errors.scm +++ b/src/scm/webid-oidc/errors.scm @@ -25,24 +25,9 @@ #:declarative? #t #:export ( - &message-for-the-user - make-message-for-the-user - message-for-the-user? - user-message - fail )) -;; A message to show the user is an XHTML paragraph or equivalent (as -;; sxml). A div is used to contain multiple messages. - -(define-exception-type - &message-for-the-user - &external-error - make-message-for-the-user - message-for-the-user? - (message user-message)) - (define (fail message) ;; Like error, but don’t do funny things when message is not a ;; string literal diff --git a/src/scm/webid-oidc/server/endpoint.scm b/src/scm/webid-oidc/server/endpoint.scm index d327139..9a19ceb 100644 --- a/src/scm/webid-oidc/server/endpoint.scm +++ b/src/scm/webid-oidc/server/endpoint.scm @@ -48,8 +48,62 @@ routed handle + + &web-exception + make-web-exception + web-exception? + web-exception-code + web-exception-reason-phrase + + &caused-by-user + make-caused-by-user + caused-by-user? + caused-by-user-webid + + &user-message + make-user-message + user-message? + user-message-sxml )) +(define-exception-type + &web-exception + &external-error + make-web-exception + web-exception? + (code web-exception-code) + (reason-phrase web-exception-reason-phrase)) + +(define-exception-type + &caused-by-user + &external-error + make-caused-by-user + caused-by-user? + (webid caused-by-user-webid)) + +(define-exception-type + &user-message + &external-error + make-user-message + user-message? + (sxml user-message-one-sxml)) + +(define (user-message-sxml exn) + (let loop ((components (simple-exceptions exn)) + (gathered '())) + (match components + (() + (match gathered + (() + `(div ,(W_ "No information available."))) + ((= reverse gathered) + `(div ,@gathered)))) + (((? user-message? (= user-message-one-sxml next)) + components ...) + (loop components `(,next ,@gathered))) + ((_ components ...) + (loop components gathered))))) + (define-class <endpoint> () (host #:init-keyword #:host #:getter host #:init-value #f) (path #:init-keyword #:path #:getter path #:init-value "/")) @@ -122,12 +176,10 @@ (let find-router ((routed (routed endpoint))) (match routed (() - (values - (build-response - #:code 404 - #:reason-phrase (W_ "Not Found")) - #f - '())) + (raise-exception + (make-exception + (make-web-exception 404 (W_ "Not Found")) + (make-user-message (W_ "The resource could not be found."))))) (((and router (? (cute relevant? <> request))) _ ...) diff --git a/src/scm/webid-oidc/token-endpoint.scm b/src/scm/webid-oidc/token-endpoint.scm index a10c843..53ff1cc 100644 --- a/src/scm/webid-oidc/token-endpoint.scm +++ b/src/scm/webid-oidc/token-endpoint.scm @@ -16,6 +16,7 @@ (define-module (webid-oidc token-endpoint) #:use-module (webid-oidc errors) + #:use-module (webid-oidc server endpoint) #:use-module (webid-oidc authorization-code) #:use-module (webid-oidc dpop-proof) #:use-module (webid-oidc jws) @@ -119,8 +120,8 @@ (xml->sxml (W_ (format #f "<p>The refresh token you sent is invalid, or it is already bound to another key.</p>"))) ((*TOP* ,p) p)) - ,@(if (message-for-the-user? error) - (user-message error) + ,@(if (user-message? error) + (list (user-message-sxml error)) '())))) port))))) ((invalid-authorization-code? error) @@ -145,8 +146,8 @@ (xml->sxml (W_ (format #f "<p>The authorization code is forged, or expired.</p>"))) ((*TOP* ,p) p)) - ,@(if (message-for-the-user? error) - (user-message error) + ,@(if (user-message? error) + (list (user-message-sxml error)) '())))) port))))) ;; Other bad request @@ -172,8 +173,8 @@ (xml->sxml (W_ (format #f "<p>The token request failed.</p>"))) ((*TOP* ,p) p)) - ,@(if (message-for-the-user? error) - (user-message error) + ,@(if (user-message? error) + (list (user-message-sxml error)) '())))) port))))))) thunk)))) @@ -231,7 +232,7 @@ (make-exception (make-unsupported-grant-type #f) (make-exception-with-message final-message) - (make-message-for-the-user final-user-message))))) + (make-user-message final-user-message))))) (receive (webid client-id) (case (string->symbol grant-type) ((authorization_code) @@ -249,7 +250,7 @@ (make-exception (make-no-authorization-code) (make-exception-with-message final-message) - (make-message-for-the-user final-user-message))))) + (make-user-message final-user-message))))) (with-exception-handler (lambda (error) (raise-exception @@ -274,7 +275,7 @@ (make-exception (make-no-refresh-token) (make-exception-with-message final-message) - (make-message-for-the-user final-user-message))))) + (make-user-message final-user-message))))) (refresh:with-refresh-token refresh-token (jwk dpop) @@ -293,7 +294,7 @@ (make-exception (make-unsupported-grant-type grant-type) (make-exception-with-message final-message) - (make-message-for-the-user final-user-message)))))) + (make-user-message final-user-message)))))) (let ((id-token (issue <id-token> issuer-key |