summaryrefslogtreecommitdiff
path: root/bin/idp
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-02-28 15:38:33 -0700
committermo khan <mo@mokhan.ca>2025-02-28 15:38:33 -0700
commit159b5abe4d26593c2442c786bebbd04829164808 (patch)
treececcfa0c15204314c978c17cdcabcbd150bd15d7 /bin/idp
parent68f60576334bb0db8c8d9c579b3d60326aaff512 (diff)
feat: add a simple grant exchange endpoint
Diffstat (limited to 'bin/idp')
-rwxr-xr-xbin/idp15
1 files changed, 14 insertions, 1 deletions
diff --git a/bin/idp b/bin/idp
index b8539014..4df50157 100755
--- a/bin/idp
+++ b/bin/idp
@@ -77,7 +77,12 @@ class IdentityProvider
when "/oauth/authorize" # RFC-6749
return post_authorize(Rack::Request.new(env))
when "/oauth/token" # RFC-6749
- return not_found
+ return [200, { 'Content-Type' => "application/json" }, [JSON.pretty_generate({
+ access_token: to_jwt(sub: SecureRandom.uuid, iat: Time.now.to_i),
+ token_type: "Bearer",
+ expires_in: 3600,
+ refresh_token: SecureRandom.hex(32)
+ })]]
when "/oauth/revoke" # RFC-7009
return not_found
else
@@ -89,6 +94,14 @@ class IdentityProvider
private
+ def to_jwt(claims)
+ [
+ Base64.strict_encode64(JSON.generate({alg: "RS256", typ: "JWT"})),
+ Base64.strict_encode64(JSON.generate(claims)),
+ Base64.strict_encode64(JSON.generate({})),
+ ].join(".")
+ end
+
# Download IDP Metadata
#
# GET /metadata.xml