summaryrefslogtreecommitdiff
path: root/src/scm/webid-oidc/errors.scm
diff options
context:
space:
mode:
authorVivien Kraus <vivien@planete-kraus.eu>2020-12-01 19:46:24 +0100
committerVivien Kraus <vivien@planete-kraus.eu>2021-06-19 15:44:36 +0200
commitdf646a0cc8f1fefd7204e08eb6754c5a85cd022a (patch)
treeb27f95b7ecf50bbf6544491fefc39f973c3c6c0a /src/scm/webid-oidc/errors.scm
parent197da00a94a2fecee59c5d7a090316e9dd82fe90 (diff)
Add an authorization code data structure
Diffstat (limited to 'src/scm/webid-oidc/errors.scm')
-rw-r--r--src/scm/webid-oidc/errors.scm87
1 files changed, 87 insertions, 0 deletions
diff --git a/src/scm/webid-oidc/errors.scm b/src/scm/webid-oidc/errors.scm
index d6f685a..879b23c 100644
--- a/src/scm/webid-oidc/errors.scm
+++ b/src/scm/webid-oidc/errors.scm
@@ -619,6 +619,74 @@
(raise-exception
((record-constructor &cannot-fetch-client-manifest) id cause)))
+(define-public &not-an-authorization-code
+ (make-exception-type
+ '&not-an-authorization-code
+ &external-error
+ '(value cause)))
+
+(define-public (raise-not-an-authorization-code value cause)
+ (raise-exception
+ ((record-constructor &not-an-authorization-code) value cause)))
+
+(define-public &not-an-authorization-code-header
+ (make-exception-type
+ '&not-an-authorization-code-header
+ &external-error
+ '(value cause)))
+
+(define-public (raise-not-an-authorization-code-header value cause)
+ (raise-exception
+ ((record-constructor &not-an-authorization-code-header) value cause)))
+
+(define-public &not-an-authorization-code-payload
+ (make-exception-type
+ '&not-an-authorization-code-payload
+ &external-error
+ '(value cause)))
+
+(define-public (raise-not-an-authorization-code-payload value cause)
+ (raise-exception
+ ((record-constructor &not-an-authorization-code-payload) value cause)))
+
+(define-public &authorization-code-expired
+ (make-exception-type
+ '&authorization-code-expired
+ &external-error
+ '(exp current-time)))
+
+(define-public (raise-authorization-code-expired exp current-time)
+ (when (integer? exp)
+ (set! exp (make-time time-utc 0 exp)))
+ (when (time? exp)
+ (set! exp (time-utc->date exp)))
+ (when (integer? current-time)
+ (set! current-time (make-time time-utc 0 current-time)))
+ (when (time? current-time)
+ (set! current-time (time-utc->date current-time)))
+ (raise-exception
+ ((record-constructor &authorization-code-expired) exp current-time)))
+
+(define-public &cannot-decode-authorization-code
+ (make-exception-type
+ '&cannot-decode-authorization-code
+ &external-error
+ '(value cause)))
+
+(define-public (raise-cannot-decode-authorization-code value cause)
+ (raise-exception
+ ((record-constructor &cannot-decode-authorization-code) value cause)))
+
+(define-public &cannot-encode-authorization-code
+ (make-exception-type
+ '&cannot-encode-authorization-code
+ &external-error
+ '(authorization-code key cause)))
+
+(define-public (raise-cannot-encode-authorization-code authorization-code key cause)
+ (raise-exception
+ ((record-constructor &cannot-encode-authorization-code) authorization-code key cause)))
+
(define*-public (error->str err #:key (max-depth #f))
(if (record? err)
(let* ((type (record-type-descriptor err))
@@ -879,6 +947,25 @@
((&cannot-fetch-client-manifest)
(format #f (G_ "I could not fetch the client manifest of ~a (because ~a)")
(uri->string (get 'id)) (recurse (get 'cause))))
+ ((&not-an-authorization-code)
+ (format #f (G_ "~s is not an authorization code (because ~a)")
+ (get 'value) (recurse (get 'cause))))
+ ((&not-an-authorization-code-header)
+ (format #f (G_ "~s is not an authorization code header (because ~a)")
+ (get 'value) (recurse (get 'cause))))
+ ((&not-an-authorization-code-payload)
+ (format #f (G_ "~s is not an authorization code payload (because ~a)")
+ (get 'value) (recurse (get 'cause))))
+ ((&authorization-code-expired)
+ (format #f (G_ "the current time is ~a, and the authorization code expired at ~a")
+ (time-second (date->time-utc (get 'current-time)))
+ (time-second (date->time-utc (get 'exp)))))
+ ((&cannot-decode-authorization-code)
+ (format #f (G_ "I cannot decode ~s as an authorization code (because ~a)")
+ (get 'value) (recurse (get 'cause))))
+ ((&cannot-encode-authorization-code)
+ (format #f (G_ "I cannot encode ~s as an authorization code (because ~a)")
+ (get 'value) (recurse (get 'cause))))
((&compound-exception)
(let ((components (get 'components)))
(if (null? components)