원클릭으로
oidc-hosted-page-angular
Implement "Sign in with SSO" in Angular SPA applications using SSOJet OIDC with PKCE.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Implement "Sign in with SSO" in Angular SPA applications using SSOJet OIDC with PKCE.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Implement Machine-to-Machine (M2M) authentication using SSOJet OAuth2 Client Credentials flow for backend services and daemons.
Implement "Sign in with SSO" in native Android/Kotlin applications using SSOJet OIDC with AppAuth.
Implement "Sign in with SSO" in ASP.NET Core applications using SSOJet OIDC middleware.
Implement "Sign in with SSO" in Go applications using SSOJet OIDC Authorization Code flow.
Implement "Sign in with SSO" in native iOS/Swift applications using SSOJet OIDC with AppAuth.
Implement "Sign in with SSO" in Java Spring Boot applications using SSOJet OIDC with Spring Security.
| name | oidc-hosted-page-angular |
| description | Implement "Sign in with SSO" in Angular SPA applications using SSOJet OIDC with PKCE. |
This expert AI assistant guide walks you through integrating "Sign in with SSO" functionality into an existing login page in an Angular application using SSOJet as an OIDC identity provider. The goal is to modify the existing login flow to add SSO support without disrupting the current traditional login functionality (e.g., email/password).
angular-auth-oidc-client.http://localhost:4200/auth/callback).Note: For SPAs, the recommended flow is Authorization Code with PKCE (no Client Secret required on the front-end).
Run the following command to install the required library:
npm install angular-auth-oidc-client
Register the OIDC module in your app.config.ts (standalone) or app.module.ts:
// app.config.ts (Standalone API - Angular 15+)
import { ApplicationConfig } from '@angular/core';
import { provideRouter } from '@angular/router';
import { provideAuth, LogLevel } from 'angular-auth-oidc-client';
import { routes } from './app.routes';
export const appConfig: ApplicationConfig = {
providers: [
provideRouter(routes),
provideAuth({
config: {
authority: 'https://auth.ssojet.com', // Your SSOJet Issuer URL
redirectUrl: 'http://localhost:4200/auth/callback',
postLogoutRedirectUri: 'http://localhost:4200/login',
clientId: 'your_client_id',
scope: 'openid profile email',
responseType: 'code',
silentRenew: true,
useRefreshToken: true,
logLevel: LogLevel.Debug,
},
}),
],
};
Create environment files for your configuration (e.g., src/environments/environment.ts):
// src/environments/environment.ts
export const environment = {
production: false,
ssojet: {
issuerUrl: 'https://auth.ssojet.com',
clientId: 'your_client_id',
redirectUri: 'http://localhost:4200/auth/callback',
},
};
Create a dedicated authentication service (e.g., src/app/services/auth.service.ts):
// src/app/services/auth.service.ts
import { Injectable } from '@angular/core';
import { OidcSecurityService } from 'angular-auth-oidc-client';
import { Observable } from 'rxjs';
@Injectable({ providedIn: 'root' })
export class AuthService {
constructor(private oidcService: OidcSecurityService) {}
get isAuthenticated$(): Observable<boolean> {
return new Observable((observer) => {
this.oidcService.isAuthenticated$.subscribe(({ isAuthenticated }) => {
observer.next(isAuthenticated);
});
});
}
get userData$() {
return this.oidcService.userData$;
}
login(loginHint?: string): void {
// Pass login_hint as an extra parameter
this.oidcService.authorize(undefined, {
customParams: { login_hint: loginHint || '' },
});
}
logout(): void {
this.oidcService.logoff();
}
checkAuth(): Observable<any> {
return this.oidcService.checkAuth();
}
}
Modify your existing login component (e.g., src/app/login/login.component.ts):
// src/app/login/login.component.ts
import { Component } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { CommonModule } from '@angular/common';
import { AuthService } from '../services/auth.service';
@Component({
selector: 'app-login',
standalone: true,
imports: [FormsModule, CommonModule],
template: `
<div class="login-container">
<h1>Sign In</h1>
<form (ngSubmit)="handleLogin()">
<div>
<label for="email">Email</label>
<input type="email" id="email" [(ngModel)]="email" name="email" required />
</div>
<div *ngIf="!isSSO">
<label for="password">Password</label>
<input type="password" id="password" [(ngModel)]="password" name="password" required />
</div>
<button type="submit">
{{ isSSO ? 'Continue with SSO' : 'Sign In' }}
</button>
</form>
<button type="button" (click)="toggleSSO()">
{{ isSSO ? 'Back to Password Login' : 'Sign in with SSO' }}
</button>
</div>
`,
})
export class LoginComponent {
isSSO = false;
email = '';
password = '';
constructor(private authService: AuthService) {}
toggleSSO(): void {
this.isSSO = !this.isSSO;
}
handleLogin(): void {
if (this.isSSO) {
// Trigger SSO login via the OIDC library
this.authService.login(this.email);
} else {
// Existing password login logic here
console.log('Processing traditional login...');
}
}
}
Create a callback component to handle the OIDC redirect (e.g., src/app/auth/callback.component.ts):
// src/app/auth/callback.component.ts
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { OidcSecurityService } from 'angular-auth-oidc-client';
@Component({
selector: 'app-auth-callback',
standalone: true,
template: `<p>Authenticating...</p>`,
})
export class AuthCallbackComponent implements OnInit {
constructor(
private oidcService: OidcSecurityService,
private router: Router
) {}
ngOnInit(): void {
this.oidcService.checkAuth().subscribe(({ isAuthenticated, userData }) => {
if (isAuthenticated) {
console.log('Authenticated User:', userData);
this.router.navigate(['/dashboard']);
} else {
this.router.navigate(['/login'], { queryParams: { error: 'oidc_failed' } });
}
});
}
}
Update your app.routes.ts to include the callback route:
// app.routes.ts
import { Routes } from '@angular/router';
import { LoginComponent } from './login/login.component';
import { AuthCallbackComponent } from './auth/callback.component';
import { DashboardComponent } from './dashboard/dashboard.component';
export const routes: Routes = [
{ path: 'login', component: LoginComponent },
{ path: 'auth/callback', component: AuthCallbackComponent },
{ path: 'dashboard', component: DashboardComponent },
{ path: '', redirectTo: '/login', pathMatch: 'full' },
];
ng serve.http://localhost:4200/login)./auth/callback and then to /dashboard.OidcSecurityService events to handle specific OIDC errors gracefully.angular-auth-oidc-client. Never store a Client Secret in the front-end.AutoLoginPartialRoutesGuard from the library to protect routes that require authentication.