-
Notifications
You must be signed in to change notification settings - Fork 45
feat(extension): browser extension core for Chrome and Firefox #418
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
Changes from all commits
1a48600
a4eec29
f040df6
ffb1aef
1a6d711
e055194
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 |
|---|---|---|
|
|
@@ -2,12 +2,15 @@ | |
|
|
||
| import java.security.interfaces.RSAPrivateKey; | ||
| import java.security.interfaces.RSAPublicKey; | ||
| import java.util.Collections; | ||
|
|
||
| import dev.findfirst.security.conditions.OAuthClientsCondition; | ||
| import dev.findfirst.security.filters.CookieAuthenticationFilter; | ||
| import dev.findfirst.security.jwt.AuthEntryPointJwt; | ||
| import dev.findfirst.security.jwt.UserAuthenticationToken; | ||
| import dev.findfirst.security.oauth2client.handlers.Oauth2LoginSuccessHandler; | ||
| import dev.findfirst.security.userauth.service.UserDetailsServiceImpl; | ||
| import dev.findfirst.security.userauth.utils.Constants; | ||
|
|
||
| import com.nimbusds.jose.jwk.JWK; | ||
| import com.nimbusds.jose.jwk.JWKSet; | ||
|
|
@@ -29,6 +32,7 @@ | |
| import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
| import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
| import org.springframework.security.config.http.SessionCreationPolicy; | ||
| import org.springframework.security.core.authority.SimpleGrantedAuthority; | ||
| import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
| import org.springframework.security.crypto.password.PasswordEncoder; | ||
| import org.springframework.security.oauth2.jwt.JwtDecoder; | ||
|
|
@@ -102,7 +106,15 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti | |
| http.csrf(csrf -> csrf.disable()) | ||
| .sessionManagement( | ||
| session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) | ||
| .oauth2ResourceServer(rs -> rs.jwt(jwt -> jwt.decoder(jwtDecoder()))); | ||
| .oauth2ResourceServer(rs -> rs.jwt(jwt -> jwt.decoder(jwtDecoder()) | ||
| .jwtAuthenticationConverter(token -> { | ||
| Number userId = token.getClaim(Constants.USER_ID_CLAIM); | ||
|
Collaborator
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. While I think this a way that works without using a JWT filter, one thing I don't like is that it bloats the config with logic. I think the better approach is either:
Personally I am okay, with accepting it as is as this doesn't break anything and leave it to myself since you're starting to get into the meat of auth/Spring. |
||
| Number roleId = token.getClaim(Constants.ROLE_ID_CLAIM); | ||
| String roleName = token.getClaim(Constants.ROLE_NAME_CLAIM); | ||
| return new UserAuthenticationToken(token.getSubject(), roleId.intValue(), | ||
| Collections.singletonList(new SimpleGrantedAuthority(roleName)), | ||
| userId.intValue()); | ||
| }))); | ||
|
|
||
| http.httpBasic( | ||
| httpBasicCustomizer -> httpBasicCustomizer.authenticationEntryPoint(unauthorizedHandler)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,14 +2,18 @@ | |
|
|
||
| import dev.findfirst.security.jwt.UserAuthenticationToken; | ||
|
|
||
| import org.springframework.security.core.Authentication; | ||
| import org.springframework.security.core.context.SecurityContextHolder; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| public class UserContext { | ||
|
|
||
| public int getUserId() { | ||
| return ((UserAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()) | ||
| .getUserId(); | ||
| Authentication auth = SecurityContextHolder.getContext().getAuthentication(); | ||
|
Collaborator
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. This is much better thank you! |
||
| if (auth instanceof UserAuthenticationToken uat) { | ||
| return uat.getUserId(); | ||
| } | ||
| throw new IllegalStateException("Unexpected authentication type: " + auth.getClass()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| package dev.findfirst.security.userauth.models; | ||
|
|
||
| public record TokenRefreshResponse(String tokenType, String refreshToken, String error) { | ||
| public TokenRefreshResponse(String refreshToken) { | ||
| this("Bearer", refreshToken, null); | ||
| public record TokenRefreshResponse(String tokenType, String accessToken, String refreshToken, String error) { | ||
| public TokenRefreshResponse(String accessToken, String refreshToken) { | ||
| this("Bearer", accessToken, refreshToken, null); | ||
|
Collaborator
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. This makes sense, does the frotend understand this update?
Collaborator
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 think its fine as is. |
||
| } | ||
| } | ||
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.
fair enough.