Skip to content

Commit

Permalink
--wip--
Browse files Browse the repository at this point in the history
  • Loading branch information
eliasjpr committed Oct 12, 2024
1 parent b5cf1e6 commit f6ff7dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/authly/grant.cr
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ module Authly
end

private def generate_id_token
if scope.includes? "openid"
if scope.includes? "openid"
payload = Authly.owners.id_token(auth_code["user_id"].as_s)
payload["iss"] = Authly.config.issuer
payload["aud"] = @client_id
payload
Authly.jwt_encode(payload)
end
end
Expand Down
9 changes: 7 additions & 2 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),
"sub" => user_id,
"iat" => Time.utc.to_unix,
"exp" => 1.hour.from_now.to_unix,
"user_id" => user_id,
"name" => user.name,
"email" => user.email
}
end

Expand Down

0 comments on commit f6ff7dd

Please sign in to comment.