-
Notifications
You must be signed in to change notification settings - Fork 632
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
OAuth2 single sign-on implementation (BE + FE) #430
Conversation
Great job ! |
…saibot94-feature-354
I've add the possibility to configure how I used Cloudfoundry uaa to test OAuth2 authentication and user info contains You can now configure attribute mapping as follow :
Can you check you can use it in your environment. I'm not able to test GroupUserMapper ? |
Thanks for that! I was actually thinking that it would've made more sense to allow the json mappings to be configurable.
I've pushed the commits that you've made onto my branches. About the error, it seems to be from some new configuration that needs to be added:
|
The I think that this feature is ready to be merged. |
That was it, apparently I was overriding those values in my I confirm that I've tested the changes on the prod instance using the Group mapper, everything is working as expected. Should I also create a PR for TheHiveDocs in the following days, documenting the functionality? |
I would be great if you write some doc about this. Thanks |
Hello @saibot94 and @To-om, I'm currently setting up the OAuth2.0 authentication. I manage to contact the authorization entity to get a token in the URL, it works successfully. However I do not succeed on the authentication part related to TheHive. (Authentication Failure) Could you please enlighten me on how to use the UserMapper feature? I am not sure how the "mappings" and "attributes" fields should be used in order to make it work.
Thanks in advance for helping me out! |
If I remember correctly, if the user data retrieved from OAuth2 server contains the role (read, write, ...) you should use "mapper=simple":
If user data contains groups, you need to map groups to roles and you should use "mapper=group":
|
Hi @To-om, Thank you so much for such a quick answer. This is so great of you and it really helped me understand how to configure it. The OAuth2 works like a charm. Once I arrive at the login page into TheHive, I can successfully connect via SSO. Immediately after, I get an authorization code in the URL which is valid, as I tested with postman. I can easily retrieve user informations to then point to the right fields in the conf file. Therefore, my configuration is as such :
I've tried numerous scenarios, even using the simple mapper where anybody should be able to access the app without success. No matter if the user exists already or not in the database, I get this error in the logs.
I am not too sure where to look at right now, my current username in thehive's elasticsearch matches the "uid" of the OAuth2 retrieved user information, which I thought could be a reason why it fails. Though, with an autocreate=true and an unregistered user in thehive's database that has permissions thanks to groups.mappings, it still fails to either create the user or connect/get past the login page. |
Another question: when configuring But it shouldn't be the case, based on your examples. Am I missing something? |
Hi @davinerd, I do not have any errors related to URLs with the configuration I used. Are you sure the Invalid URL doesn't come from the OAuth2's redirect URL or any other parameter and not the sso field? Make sure to verify fields such as :
Feel free to share more logs and info on your application.conf it it doesn't help. As for my situation, I still haven't fixed it. |
I am having the same issue with invalid url. I am using a 3.4.0-RC1 Hive veversion, please find my logs below: [error] o.e.s.a.MultiAuthSrv - Authentication failure |
$scope.ssoLogin = function (code) { | ||
AuthenticationSrv.ssoLogin(code, function(data, status, headers) { | ||
var redirectLocation = headers().location; | ||
if(angular.isDefined(redirectLocation)) { |
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.
@saibot94 Could you explain what does this line? I mean: I understand that it takes the Location
header of the response and redirect to it, but I don't understand why.
This PR addresses feature request #354 .
The related elastic4play PR can be found here.
It adds a few pieces of functionality (described below) in order to allow smooth integration for any custom OAuth2 server that you may use.
UI changes
In order to support OAuth2 login, the currently existing login page wouldn't be sufficient. Once an SSO method is detected, the SSO login button is displayed on the UI:
The changes include the possibility of automatically redirecting users to the organization's SSO page when accessing the root url of the site, through a config parameter.
Thus, accessing http://my-thehive-instance.com/ would redirect the user to the OAuth2 provider.
Backend changes
The
OAuth2Srv
is the bread and butter of the PR, providing a new auth method that can be added to the list of others.A new endpoint is provided, allowing the use of the
authenticate()
method and not interfering with the other regular logins:The concept of a
UserMapper
is also introduced, allowing you to easily define a 1-1 mapping from the response that the OAuth2 to user fields, such that user. Two different simple UserMapper implementations (that made sense for us) are included:Configuration changes
Currently, the only OAuth2
responseType
available iscode
, returning a GET param in the form?id=some-oauth-code-here
.Below is an example of how the config file's auth portion would look like, should one choose to setup OAuth and the GroupMapper:
Comments, suggestions, improvements are always welcome.
PS: I'll change the version from
Dependencies.scala
once theelastic4play
PR gets accepted first.PS2: Once everything's OK on your side, as well, I'll submit a PR for the documentation as well, in order to keep it all consistent.