Skip to content

Commit

Permalink
Enhance ID token with client ID and owner details
Browse files Browse the repository at this point in the history
Added `aud` field to the ID token, setting it to the client ID, ensuring proper audience specification. Enhanced owner struct to include `name` and `email`, and incorporated these details into the ID token. This improves alignment with OpenID Connect standards and enhances traceability by providing more detailed user information.
  • Loading branch information
eliasjpr committed Oct 18, 2024
1 parent ee2cb48 commit e668eb1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/authly/grant.cr
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ module Authly
if scope.includes? "openid"
payload = Authly.owners.id_token(auth_code["user_id"].as_s)
payload["iss"] = Authly.config.issuer
payload["aud"] = @client_id
Authly.jwt_encode(payload)
end
end
Expand Down
13 changes: 9 additions & 4 deletions src/authly/owner.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module Authly
struct Owner
property id : String = Random::Secure.hex(16)
property name : String = ""
property email : String = ""
property username : String
property password : String

Expand All @@ -26,11 +29,13 @@ module Authly
end

def id_token(user_id : String) : Hash(String, String | Int64)
user = find! { |owner| owner.id == user_id }
{
"sub" => Random::Secure.hex(32),
"iat" => Time.utc.to_unix,
"exp" => 1.hour.from_now.to_unix,
"user_id" => user_id,
"sub" => user_id,
"iat" => Time.utc.to_unix,
"exp" => 1.hour.from_now.to_unix,
"name" => user.name,
"email" => user.email,
}
end

Expand Down

0 comments on commit e668eb1

Please sign in to comment.