-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(openid-connect): the default 'redirect_uri' (#2426) #7690
Changes from 2 commits
674b85e
4af8303
75abdd0
02b0707
d4f158a
9d11f55
46ecafd
af8d34b
b375f9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,7 +86,7 @@ local schema = { | |
}, | ||
redirect_uri = { | ||
type = "string", | ||
description = "use ngx.var.request_uri if not configured" | ||
description = "auto append '.apisix/redirect' if not configured" | ||
monkeyDluffy6017 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
post_logout_redirect_uri = { | ||
type = "string", | ||
|
@@ -357,7 +357,22 @@ function _M.rewrite(plugin_conf, ctx) | |
end | ||
|
||
if not conf.redirect_uri then | ||
conf.redirect_uri = ctx.var.request_uri | ||
-- NOTE: 'lua-resty-openidc' requires that 'redirect_uri' be | ||
-- different from 'uri'. So default to append the | ||
-- '.apisix/redirect' suffix if not configured. | ||
local suffix = "/.apisix/redirect" | ||
local uri = ctx.var.uri | ||
if core.string.has_suffix(uri, suffix) then | ||
-- This is the redirection response from the OIDC provider. | ||
conf.redirect_uri = uri | ||
else | ||
if string.sub(uri, -1, -1) == "/" then | ||
conf.redirect_uri = string.sub(uri, 1, -2) .. suffix | ||
else | ||
conf.redirect_uri = uri .. suffix | ||
end | ||
end | ||
core.log.debug("auto set redirect_uri: ", conf.redirect_uri) | ||
Comment on lines
+360
to
+375
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When there is no Can we inject a default value for For example:
Listen to what others say. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @liweitianux any thoughts about this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we can set a proper default value for Please correct me if I'm mistaken. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with you. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need a test case to show that not providing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed the job this year, and I haven't been working with APISIX for more than one year now. I'm unfamiliar with the test framework, and that was the main reason that this PR was lacking a test case. It would be great if you can rejuvenate this PR. Thanks. |
||
end | ||
|
||
if not conf.ssl_verify then | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -44,7 +44,7 @@ description: OpenID Connect allows the client to obtain user information from th | |||||
| bearer_only | boolean | False | false | | When set to `true`, APISIX will only check if the authorization header in the request matches a bearer token. | | ||||||
| logout_path | string | False | "/logout" | | Path for logging out. | | ||||||
| post_logout_redirect_uri | string | False | | | URL to redirect to after logging out. | | ||||||
| redirect_uri | string | False | "ngx.var.request_uri" | | URI to which the identity provider redirects back to. | | ||||||
| redirect_uri | string | False | | | URI to which the identity provider redirects back to. If not configured, APISIX will append the `.apisix/redirect` suffix to determine the default `redirect_uri`. Note that the provider should be properly configured to allow such `redirect_uri` values. | | ||||||
| timeout | integer | False | 3 | [1,...] | Request timeout time in seconds. | | ||||||
| ssl_verify | boolean | False | false | | When set to true, verifies the identity provider's SSL certificates. | | ||||||
| introspection_endpoint | string | False | | | URL of the token verification endpoint of the identity server. | | ||||||
|
@@ -211,3 +211,4 @@ In this example, the Plugin can enforce that the access token, the ID token, and | |||||
|
||||||
- `redirect_uri` needs to be captured by the route where the current APISIX is located. For example, the `uri` of the current route is `/api/v1/*`, `redirect_uri` can be filled in as `/api/v1/callback`; | ||||||
- `scheme` and `host` of `redirect_uri` (`scheme:host`) are the values required to access APISIX from the perspective of the identity provider. | ||||||
- See also [this GitHub issue](https://github.com/apache/apisix/issues/2426), especially these comments: [@starsz](https://github.com/apache/apisix/issues/2426#issuecomment-1091021687), [@david-woelfle](https://github.com/apache/apisix/issues/2426#issuecomment-1090675455), [@liweitianux (1)](https://github.com/apache/apisix/issues/2426#issuecomment-1206107085), [@liweitianux (2)](https://github.com/apache/apisix/issues/2426#issuecomment-1207423283) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you write the conclusion in a short sentence, instead of multiple reference links? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it cannot make sure the new URI will be matched by the same route, it actually adds an implicit condition that the route match type is prefix instead of exact.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well. If the route is of type exact, then it cannot actually use this
openid-connect
plugin, because theredirect_uri
must be different from the request URI, as required bylua-resty-openidc
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liweitianux Could you write some hints about this in the OpenID Connect doc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. I'll update the doc later.