Skip to content

Commit

Permalink
Code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
eliasjpr committed Oct 9, 2024
1 parent 91e97e7 commit c5b9188
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
8 changes: 4 additions & 4 deletions spec/authly_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ describe Authly do

token.should eq({
"active" => true,
"scope" => scope,
"cid" => client_id,
"exp" => a_token.expires_in,
"sub" => expected_token["sub"],
"scope" => scope,
"cid" => client_id,
"exp" => a_token.expires_in,
"sub" => expected_token["sub"],
})
end

Expand Down
2 changes: 1 addition & 1 deletion src/authly/error.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Authly
unsupported_grant_type: "Invalid or unknown grant type",
access_denied: "The user or authorization server denied the request",
unsupported_token_type: "The authorization server does not support the presented token type",
invalid_token: "The token is invalid or expired",
invalid_token: "The token is invalid or expired",
}

class Error(Code) < Exception
Expand Down
27 changes: 12 additions & 15 deletions src/authly/token_manager.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Authly

class TokenStrategyFactory
TOKEN_MANAGERS = {
jwt: JWTToken.new,
jwt: JWTToken.new,
opaque: OpaqueToken.new,
}

Expand Down Expand Up @@ -52,19 +52,19 @@ module Authly

# Check if the token is expired (exp claim is typically in seconds since epoch)
if Time.local.to_unix > payload["exp"].to_s.to_i
return {"active" => false, "exp"=> payload["exp"].as_i64}
return {"active" => false, "exp" => payload["exp"].as_i64}
end

# Return authly access token
{
"active"=> true,
"scope"=> payload["scope"].as_s,
"cid"=> payload["cid"].as_s,
"exp"=> payload["exp"].as_i64,
"sub"=> payload["sub"].as_s,
"active" => true,
"scope" => payload["scope"].as_s,
"cid" => payload["cid"].as_s,
"exp" => payload["exp"].as_i64,
"sub" => payload["sub"].as_s,
}
rescue JWT::DecodeError
{"active"=> false}
{"active" => false}
end
end

Expand All @@ -89,17 +89,15 @@ module Authly
end

def introspect(token : String)
payload = @token_store.fetch(token)
return {"active"=> false} if payload.nil?

{"active"=> true, "token"=> payload}
payload = @token_store.fetch(token)
return {"active" => false} if payload.nil?

{"active" => true, "token" => payload}
rescue e : Error
{"active"=> false}
{"active" => false}
end
end


class TokenManager
def self.instance
@@instance ||= new
Expand All @@ -126,6 +124,5 @@ module Authly
def introspect(token : String)
@token_manager.introspect(token)
end

end
end

0 comments on commit c5b9188

Please sign in to comment.