Skip to content

Commit

Permalink
verify in pub key
Browse files Browse the repository at this point in the history
  • Loading branch information
Revolyssup committed Feb 28, 2025
1 parent adf5af6 commit 580a515
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
20 changes: 9 additions & 11 deletions apisix/plugins/openid-connect.lua
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,15 @@ local function introspect(ctx, conf)
return nil, nil, nil, nil
end
end
local opts = {}
-- If we get here, token was found in request.
if conf.use_jwks then

if conf.public_key or conf.use_jwks then
local opts = {}
-- Validate token against public key or jwks document of the oidc provider.
-- TODO: In the called method, the openidc module will try to extract
-- the token by itself again -- from a request header or session cookie.
-- It is inefficient that we also need to extract it (just from headers)
-- so we can add it in the configured header. Find a way to use openidc
-- module's internal methods to extract the token.
local valid_issuers
if conf.valid_issuers then
valid_issuers = conf.valid_issuers
Expand All @@ -402,14 +408,6 @@ local function introspect(ctx, conf)
if valid_issuers then
opts.valid_issuers = valid_issuers
end
end
if conf.public_key or conf.use_jwks then
-- Validate token against public key or jwks document of the oidc provider.
-- TODO: In the called method, the openidc module will try to extract
-- the token by itself again -- from a request header or session cookie.
-- It is inefficient that we also need to extract it (just from headers)
-- so we can add it in the configured header. Find a way to use openidc
-- module's internal methods to extract the token.
local res, err = openidc.bearer_jwt_verify(conf, opts)
if err then
-- Error while validating or token invalid.
Expand Down
2 changes: 0 additions & 2 deletions t/plugin/jwt-auth2.t
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ hello world
"openid-connect": {
"client_id": "kbyuFDidLLm280LIwVFiazOqjO3ty8KH",
"client_secret": "60Op4HFM0I8ajz0WdiStAbziZ-VFQttXuxixHHs2R7r7-CW8GR79l-mmLqMhc-Sa",
"discovery": "https://samples.auth0.com/.well-known/openid-configuration",
"redirect_uri": "https://iresty.com",
"ssl_verify": false,
"timeout": 10,
Expand Down Expand Up @@ -312,7 +311,6 @@ qr/ailed to verify jwt: 'exp' claim expired at/
"openid-connect": {
"client_id": "kbyuFDidLLm280LIwVFiazOqjO3ty8KH",
"client_secret": "60Op4HFM0I8ajz0WdiStAbziZ-VFQttXuxixHHs2R7r7-CW8GR79l-mmLqMhc-Sa",
"discovery": "https://samples.auth0.com/.well-known/openid-configuration",
"redirect_uri": "https://iresty.com",
"ssl_verify": false,
"timeout": 10,
Expand Down
4 changes: 0 additions & 4 deletions t/plugin/openid-connect.t
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,6 @@ OIDC introspection failed: Invalid Authorization header format.
"openid-connect": {
"client_id": "kbyuFDidLLm280LIwVFiazOqjO3ty8KH",
"client_secret": "60Op4HFM0I8ajz0WdiStAbziZ-VFQttXuxixHHs2R7r7-CW8GR79l-mmLqMhc-Sa",
"discovery": "https://samples.auth0.com/.well-known/openid-configuration",
"redirect_uri": "https://iresty.com",
"ssl_verify": false,
"timeout": 10,
Expand Down Expand Up @@ -538,7 +537,6 @@ true
"openid-connect": {
"client_id": "kbyuFDidLLm280LIwVFiazOqjO3ty8KH",
"client_secret": "60Op4HFM0I8ajz0WdiStAbziZ-VFQttXuxixHHs2R7r7-CW8GR79l-mmLqMhc-Sa",
"discovery": "https://samples.auth0.com/.well-known/openid-configuration",
"redirect_uri": "https://iresty.com",
"ssl_verify": false,
"timeout": 10,
Expand Down Expand Up @@ -604,7 +602,6 @@ x-userinfo: ey.*
"openid-connect": {
"client_id": "kbyuFDidLLm280LIwVFiazOqjO3ty8KH",
"client_secret": "60Op4HFM0I8ajz0WdiStAbziZ-VFQttXuxixHHs2R7r7-CW8GR79l-mmLqMhc-Sa",
"discovery": "https://samples.auth0.com/.well-known/openid-configuration",
"redirect_uri": "https://iresty.com",
"ssl_verify": false,
"timeout": 10,
Expand Down Expand Up @@ -672,7 +669,6 @@ x-real-ip: 127.0.0.1
"openid-connect": {
"client_id": "kbyuFDidLLm280LIwVFiazOqjO3ty8KH",
"client_secret": "60Op4HFM0I8ajz0WdiStAbziZ-VFQttXuxixHHs2R7r7-CW8GR79l-mmLqMhc-Sa",
"discovery": "https://samples.auth0.com/.well-known/openid-configuration",
"redirect_uri": "https://iresty.com",
"ssl_verify": false,
"timeout": 10,
Expand Down

0 comments on commit 580a515

Please sign in to comment.