Fetch user role from oauth app in authentication response - spring

We are using Okta as a OAuth login provider.
What we wish to achieve is to fetch user role information in the authentication response itself. We are using spring security.
Currently we get following details in org.springframework.security.oauth2.core.oidc.user.OidcUser object
[Edit]
Adding content of authorities
This does not include user role information. Is there a way to get the user role information in the authentication response itself?

Related

Connect to Ldap and Authenticate user with asp.net web api

I have to authenticate my user credentials in my asp.NET web api with ldap server and if success token is given have to check whether the user has access to controller with another table with contains user role and id
I have tried with token based authentication but could not implement the table authorization part

Auth0 with Authorization Extension not passing roles to Spring Security JWT object

I have an Auth0 project that I am using for authentication. I have modeled my Spring code based on this example.
I am trying to limit an area like this...
.antMatchers(ADMIN).hasRole(Role.ADMIN.getRoleName())
But when I add my Admin role to my user and try to log back in the JWT does not show any roles when I run...
Collection<SimpleGrantedAuthority> authorities = (Collection<SimpleGrantedAuthority>) SecurityContextHolder.getContext().getAuthentication().getAuthorities();
It is empty. How do I pass the roles to my application using Auth0
More Information
I tried decoding the JWT token and I don't see the role information even being passed....
Header
{"typ":"JWT","alg":"RS256","kid":"<Removed>"}
Body
{"iss":<Removed>,"sub":<Removed>,"aud":<removed>,"iat":<removed>,"exp":<removed>}
So why is Auth0 not passing this information.
Groups, roles and permissions won't be added to the jwt automatically. You have to
create a new rule or modify the default rule which is created after enabling (publishing) the authorization extension.
Adding roles and permissions to a JWT access token in Auth0
You should provide the granted authorities to your principal when you're authenticating it.
I assume you have a custom class that implements UserDetails and you overwrite getAuthorities(). This method should return an authority called ROLE_ADMIN. Notice that the role should be prefixed with ROLE_

Where to fetch user roles using ADFS service

I'm newbie to ADFS and I need to enable my web application developed with Spring Security to use ADFS service for user authentication and authorization, I've figured out the authentication process but it's the authorization piece is blocking me, actually, I'm confused, from where to get user roles? Because my datastore (mongoDB) neither have user info and roles which is required for securing my rest resources, can someone enlighten me how to implement same.
In the ADFS wizard, you configure claims rules which place AD attributes in the token.
Some of these attributes can be roles which you can then use for authorisation.
That's assuming that there are some roles in the AD?
You can also use the claims rules to get attributes from your DB.

springboot oauth access token validation with user details before api call

i am working on springboot architecture with oauth security.
And we have authorization server and resource server.
All are working fine.
Here we need to authorize user on every api call.
The issue scenario is -we hit the api with user1 accesstoken,but we are able to get the user2 information with the same user1 access token.
It will reduce security for the user information.
So how can we handle this scenario?
where we need to configure this setttings for validate the accesstoken with the corresponding user?
We need a solution like
user1 accesstoken only able to get the user1 information,not able to get the user2 information..
Thanks,
Arunraj M
Spring security provides only method level authorities, for example if you have a method called getAllUsers(), and for the user you have created a token have access to this method should able to get all the user details.
If you want to filter further, then implement JWTtokens and from the token you can get the user for which the token is been generated, from that you can write a filter to get a appropriate value

Issue token to logged in user via spring

I have a Spring (3.2) based web app that a user can log into. The site will also provide an API secured via OAuth 2.0. My question then, is how do I go about generating a token for a logged in user?
The underlying idea here is that there will be a mobile app that opens up a web frame to the login page, which will eventually redirect to a url schema with an oauth token that the app will catch and then use for the api calls. Looking at the code for TokenEndpoint, I see that it defers token creation to a list of TokenGranter types. Should I be creating my own TokenGranter extended class, or am I looking at this all wrong?
I ended up writing a controller like this:
OAuthClientRequest request = OAuthClientRequest
.authorizationLocation(csOauthAuthorizeUrl)
.setClientId(csClientId)
.setRedirectURI(
UrlLocator.getBaseUrlBuilder().addSubpath(AUTH_CODE_HANDLER_URL).asUnEscapedString())
.setResponseType("code")
.buildQueryMessage();
UrlUtils.temporarilyRedirect(httpResponse, request.getLocationUri());
return null;
Then handling the code returned. My big problem here was that I had the /oauth/authorize endpoint set to use client credentials. Once I realized that tokens were being issued for the client ID instead of the user, it started to make sense.
So you want to use the Authorization Flow of OAuth. Spring has already support that, if you have configured the spring-security-oauth correctly, you just have to redirect the user/your mobile apps to /oauth/authorize?client_id=xxx&response_type=code this will redirect user to authorization page, if user has not login yet, it will redirect the user to login page then to the authorization page.
After the user completed the authorization process, it will redirect the user to an already registered redirect_url parameter with the authorization_code 'yourapp.com/callback?code=xxxx'.
Your application should exchange this authorization_code with the real token access to /oauth/token?grant_type=authorization_code&code=xxxx&client_id=xxxx&client_secret=xxxx
After that you will receive the token access that can be used to access the resource server.

Resources