-
Notifications
You must be signed in to change notification settings - Fork 27
OIDC-243: API Access using Accesstoken #86
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
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ | |
| import java.net.URLEncoder; | ||
|
|
||
| import javax.script.ScriptContext; | ||
| import javax.servlet.http.HttpServletRequest; | ||
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.slf4j.Logger; | ||
|
|
@@ -55,7 +56,7 @@ | |
|
|
||
| /** | ||
| * Authenticate user trough an OpenID Connect provider. | ||
| * | ||
| * | ||
| * @version $Id$ | ||
| */ | ||
| public class OIDCAuthServiceImpl extends XWikiAuthServiceImpl | ||
|
|
@@ -85,6 +86,21 @@ public XWikiUser checkAuth(XWikiContext context) throws XWikiException | |
| XWikiUser user = super.checkAuth(context); | ||
|
|
||
| if (user == null) { | ||
| // obtain user from authorization header | ||
| if (configuration.isAllowAccessToken()) { | ||
| HttpServletRequest request = context.getRequest().getHttpServletRequest(); | ||
| String idTokenHeader = request.getHeader("X-Id-Token"); | ||
| String accessTokenHeader = request.getHeader("X-Access-Token"); | ||
|
|
||
| if (idTokenHeader != null && accessTokenHeader != null) { | ||
|
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. Seems to me the ID token should be optional (I'm not even sure it's needed at all actually as there is probably a way to request an ID token from the provider, with the access token). 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 looked into this and have not found a way to get one. |
||
| // validate JWT | ||
| user = users.checkAccessToken(idTokenHeader, accessTokenHeader); | ||
| if (user != null) { | ||
| return user; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| LOGGER.debug("No user could be found in the session, starting an OpenID Connect authentication"); | ||
|
|
||
| // Try OIDC if there is no already authenticated user | ||
|
|
||
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.
Wouldn't it make more sense to receive the access token as a Bearer Authorization header ?
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.
That could certainly be done this way. But for the Authorization header I would expect that single header to be sufficient for authorization, thou we would have to combine the two tokens. And sending the id token is non-standard anyways. I would prefer to leave it as-is.