Skip to content
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

feat(ui, server): Generic SSO OAuth2 OpenID Connect #188

Closed
wants to merge 26 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
fa39410
[WIP] feat(ui, server): Generic SSO OAuth2 OpenID Connect
DelaunayAlex Oct 1, 2024
6988c7c
[WIP] feat(server, ui): Conf SSO OAuth2
DelaunayAlex Oct 3, 2024
8c5d14f
feat(server, ui): SSO OAuth2 with mock oidc-provider, authenticate SS…
DelaunayAlex Oct 10, 2024
0e8ac00
feat(server, ui): SSO OAuth2 with mock oidc-provider, authenticate SS…
DelaunayAlex Oct 10, 2024
b492609
feat(ui, server): Doc local oidc provider
DelaunayAlex Oct 14, 2024
9ffca82
feat(server, ui): Fix PR
DelaunayAlex Oct 20, 2024
e9f42b4
feat(server, ui): Add licence
DelaunayAlex Oct 22, 2024
1fa05b0
feat(ui): Use app initializer
DelaunayAlex Oct 22, 2024
0853d58
feat(server, ui): Fix PR
DelaunayAlex Oct 29, 2024
583c67c
feat(server): Add proxy
DelaunayAlex Oct 30, 2024
fb4efde
feat(ui): Update headers OAuth2
DelaunayAlex Nov 4, 2024
d8b7122
feat(ui): Update headers OAuth2
DelaunayAlex Nov 4, 2024
0e7caa2
feat(ui): SSO : Replace idToken with accessToken
DelaunayAlex Nov 6, 2024
975bf19
feat(ui, server): Ui parameter via server, add logo sso
DelaunayAlex Nov 6, 2024
d4029d4
[WIP] feat(ui, server): add param id_token_hint
DelaunayAlex Nov 6, 2024
562b35b
[WIP] feat(ui, server): add param id_token_hint
DelaunayAlex Nov 6, 2024
5b6fcc3
feat(ui): fix logout sso
DelaunayAlex Nov 7, 2024
4645511
feat(ui): SSO : Fix redirect uri
DelaunayAlex Nov 12, 2024
8fb7b70
feat(ui): fix retry sso
DelaunayAlex Nov 12, 2024
c7d26f2
feat(ui): fix test
DelaunayAlex Nov 13, 2024
56ccf36
feat(ui): fix PR
DelaunayAlex Nov 14, 2024
33c2a05
feat(ui): fix PR
DelaunayAlex Nov 19, 2024
95e6a5d
chore(): Allow to test sso with a local-dev server running on 8443
boddissattva Nov 20, 2024
8f51a23
chore(): Clean and fix flaky test
boddissattva Nov 20, 2024
36ddfb2
chore(): Fix flaky test
boddissattva Nov 20, 2024
5a38e60
feat(ui, server): Alert message when sso auth fails, fix PR
DelaunayAlex Nov 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(server, ui): SSO OAuth2 with mock oidc-provider, authenticate SS…
…O Opaque token and generate session on server side
DelaunayAlex committed Nov 19, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 0e8ac003c88b6bd6bf8075eb2bd92e1e98f75aea
Original file line number Diff line number Diff line change
@@ -9,11 +9,11 @@

import org.springframework.security.authentication.AbstractAuthenticationToken;

public class TokenAuthenticationToken extends AbstractAuthenticationToken {
public class OAuth2AuthenticationToken extends AbstractAuthenticationToken {

private final String token;

public TokenAuthenticationToken(String token) {
public OAuth2AuthenticationToken(String token) {
super(null);
this.token = token;
setAuthenticated(false);
Original file line number Diff line number Diff line change
@@ -93,28 +93,28 @@ SsoOpenIdConnectConfig ssoOpenIdConnectConfig(

@Bean
public OAuth2UserService<OAuth2UserRequest, OAuth2User> customOAuth2UserService(AuthenticationService authenticationService) {
return new CustomOAuth2UserService(authenticationService);
return new OAuth2SsoUserService(authenticationService);
}

@Bean
public TokenAuthenticationProvider tokenAuthenticationProvider(AuthenticationService authenticationService, ClientRegistrationRepository clientRegistrationRepository) {
return new TokenAuthenticationProvider(customOAuth2UserService(authenticationService), clientRegistrationRepository.findByRegistrationId("my-provider"));
public OAuth2TokenAuthenticationProvider tokenAuthenticationProvider(AuthenticationService authenticationService, ClientRegistrationRepository clientRegistrationRepository) {
return new OAuth2TokenAuthenticationProvider(customOAuth2UserService(authenticationService), clientRegistrationRepository.findByRegistrationId("my-provider"));
}

@Bean
public AuthenticationManager authenticationManager(TokenAuthenticationProvider tokenAuthenticationProvider) {
return new ProviderManager(Collections.singletonList(tokenAuthenticationProvider));
public AuthenticationManager authenticationManager(OAuth2TokenAuthenticationProvider OAuth2TokenAuthenticationProvider) {
return new ProviderManager(Collections.singletonList(OAuth2TokenAuthenticationProvider));
}

@Bean
@Order(1)
public SecurityFilterChain securityFilterChainOAuth2Sso(final HttpSecurity http, TokenAuthenticationProvider tokenAuthenticationProvider, AuthenticationManager authenticationManager) throws Exception {
public SecurityFilterChain securityFilterChainOAuth2Sso(final HttpSecurity http, OAuth2TokenAuthenticationProvider OAuth2TokenAuthenticationProvider, AuthenticationManager authenticationManager) throws Exception {
ChutneyWebSecurityConfig chutneyWebSecurityConfig = new ChutneyWebSecurityConfig();
TokenAuthenticationFilter tokenFilter = new TokenAuthenticationFilter(authenticationManager);
OAuth2TokenAuthenticationFilter tokenFilter = new OAuth2TokenAuthenticationFilter(authenticationManager);
chutneyWebSecurityConfig.configureBaseHttpSecurity(http, sslEnabled);
UserDto anonymous = chutneyWebSecurityConfig.anonymous();
http
.authenticationProvider(tokenAuthenticationProvider)
.authenticationProvider(OAuth2TokenAuthenticationProvider)
.addFilterBefore(tokenFilter, BasicAuthenticationFilter.class)
.anonymous(anonymousConfigurer -> anonymousConfigurer
.principal(anonymous)
Original file line number Diff line number Diff line change
@@ -15,22 +15,21 @@
import java.util.Map;
import org.springframework.security.oauth2.client.userinfo.DefaultOAuth2UserService;
import org.springframework.security.oauth2.client.userinfo.OAuth2UserRequest;
import org.springframework.security.oauth2.client.userinfo.OAuth2UserService;
import org.springframework.security.oauth2.core.OAuth2AuthenticationException;
import org.springframework.security.oauth2.core.user.DefaultOAuth2User;
import org.springframework.security.oauth2.core.user.OAuth2User;

public class CustomOAuth2UserService implements OAuth2UserService<OAuth2UserRequest, OAuth2User> {
public class OAuth2SsoUserService implements org.springframework.security.oauth2.client.userinfo.OAuth2UserService<OAuth2UserRequest, OAuth2User> {

private final AuthenticationService authenticationService;

public CustomOAuth2UserService(AuthenticationService authenticationService) {
public OAuth2SsoUserService(AuthenticationService authenticationService) {
this.authenticationService = authenticationService;
}

@Override
public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2AuthenticationException {
OAuth2UserService<OAuth2UserRequest, OAuth2User> delegate = new DefaultOAuth2UserService();
org.springframework.security.oauth2.client.userinfo.OAuth2UserService<OAuth2UserRequest, OAuth2User> delegate = new DefaultOAuth2UserService();
OAuth2User oAuth2User = delegate.loadUser(userRequest);
Map<String, Object> oAuth2UserAttributes = oAuth2User.getAttributes();
String username = (String) oAuth2UserAttributes.get("sub");
Original file line number Diff line number Diff line change
@@ -19,11 +19,11 @@
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.filter.OncePerRequestFilter;

public class TokenAuthenticationFilter extends OncePerRequestFilter {
public class OAuth2TokenAuthenticationFilter extends OncePerRequestFilter {

private final AuthenticationManager authenticationManager;

public TokenAuthenticationFilter(AuthenticationManager authenticationManager){
public OAuth2TokenAuthenticationFilter(AuthenticationManager authenticationManager){
this.authenticationManager = authenticationManager;
}

@@ -35,7 +35,7 @@ protected void doFilterInternal(HttpServletRequest request,
String authorizationHeader = request.getHeader(HttpHeaders.AUTHORIZATION);
if (authorizationHeader != null && authorizationHeader.startsWith("Bearer ")) {
String token = authorizationHeader.substring(7);
TokenAuthenticationToken authRequest = new TokenAuthenticationToken(token);
OAuth2AuthenticationToken authRequest = new OAuth2AuthenticationToken(token);
try {
Authentication authentication = authenticationManager.authenticate(authRequest);
SecurityContextHolder.getContext().setAuthentication(authentication);
Original file line number Diff line number Diff line change
@@ -18,19 +18,19 @@
import org.springframework.security.oauth2.core.OAuth2AccessToken;
import org.springframework.security.oauth2.core.user.OAuth2User;

public class TokenAuthenticationProvider implements AuthenticationProvider {
public class OAuth2TokenAuthenticationProvider implements AuthenticationProvider {

private final OAuth2UserService<OAuth2UserRequest, OAuth2User> oAuth2UserService;
private final ClientRegistration clientRegistration;

public TokenAuthenticationProvider(OAuth2UserService<OAuth2UserRequest, OAuth2User> oAuth2UserService, ClientRegistration clientRegistration) {
public OAuth2TokenAuthenticationProvider(OAuth2UserService<OAuth2UserRequest, OAuth2User> oAuth2UserService, ClientRegistration clientRegistration) {
this.oAuth2UserService = oAuth2UserService;
this.clientRegistration = clientRegistration;
}

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
TokenAuthenticationToken tokenAuth = (TokenAuthenticationToken) authentication;
OAuth2AuthenticationToken tokenAuth = (OAuth2AuthenticationToken) authentication;
String token = tokenAuth.getCredentials().toString();
OAuth2AccessToken accessToken = new OAuth2AccessToken(OAuth2AccessToken.TokenType.BEARER, token, null, null);
OAuth2UserRequest userRequest = new OAuth2UserRequest(clientRegistration, accessToken);
@@ -44,6 +44,6 @@ public Authentication authenticate(Authentication authentication) throws Authent

@Override
public boolean supports(Class<?> authentication) {
return TokenAuthenticationToken.class.isAssignableFrom(authentication);
return OAuth2AuthenticationToken.class.isAssignableFrom(authentication);
}
}
7 changes: 2 additions & 5 deletions chutney/ui/src/app/core/guards/auth.guard.ts
Original file line number Diff line number Diff line change
@@ -11,11 +11,8 @@ import { TranslateService } from '@ngx-translate/core';

import { LoginService } from '@core/services';
import { AlertService } from '@shared';
import {Authorization, User} from '@model';
import {OAuthService} from "angular-oauth2-oidc";
import {SsoOpenIdConnectService} from "@core/services/sso-open-id-connect.service";
import {HttpHeaders} from "@angular/common/http";
import {firstValueFrom} from "rxjs";
import { Authorization } from '@model';
import { firstValueFrom } from "rxjs";


export const authGuard: CanActivateFn = async (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => {
2 changes: 0 additions & 2 deletions chutney/ui/src/app/core/services/login.service.ts
Original file line number Diff line number Diff line change
@@ -128,11 +128,9 @@ export class LoginService {
[header: string]: string | string[];
} = {}): Observable<User> {
const headersInterceptor = skipInterceptor ? { 'no-intercept-error': ''} : {}
console.log(headers)
const options = {
headers: { ...headersInterceptor, ...headers}
};
console.log(options)
return this.http.get<User>(environment.backend + this.url, options);
}