This Angular project provides a robust implementation of authentication using OpenID Connect (OIDC) and OAuth2 standards. It is designed to help developers quickly integrate secure authentication flows into their Angular applications.
- OIDC and OAuth2 integration using
angular-oauth2-oidc
. - Protected routes with
AuthGuard
. - Centralized authentication service (
AuthService
). - Modular Angular architecture.
- Node.js
- Angular CLI
- Clone the repository: git clone https://github.com/santagatiivan/Angular-SSO-OAuth2-OIDC.git
- Install dependencies:
cd <project-name>
and thannpm install
This file is the root module of the Angular application. It imports essential Angular modules, including BrowserModule
for running the app in a web browser and AppRoutingModule
for routing. It declares AppComponent
as the main component that will bootstrap when the app starts.
Defines the routes of the application. It uses AuthGuard
to protect the /dashboard
route, ensuring that only authenticated users can access it. The AuthGuard
service checks if the user is logged in before allowing access to the route.
Implements the CanActivate
interface to guard routes. It uses AuthService
to check if the user is logged in. If not, it redirects the user to the login page, ensuring secure access to protected routes.
Provides authentication services using the angular-oauth2-oidc
library. It configures the OAuth service with the application's specific settings (issuer, client ID, etc.) and includes methods for logging in and out. The service also exposes a method to check if the user is currently logged in.
app.component.ts
serves as the root component of the application. It contains a method to initiate the login process. app.component.html
provides the template, displaying a login button that triggers the authentication flow when clicked.
After successful authentication, the user is directed to the Dashboard, represented by dashboard.component.ts
and its template dashboard.component.html
. The dashboard simply displays a success message and includes a logout button, illustrating a basic post-login user interface.
These files provide configuration settings for different aspects of the application, such as routing and server-side rendering optimizations. They are designed to be modified as per the deployment environment's requirements.
- Update
auth.service.ts
with your OIDC/OAuth2 provider details:
issuer
clientId
redirectUri
scope
- Configure route guards as needed in
app-routing.module.ts
.
- Start the Angular development server:
ng serve
- Open
http://localhost:4200/
in your browser.
Please refer to CONTRIBUTING.md
for details on how to contribute to this project.
This project is licensed under the MIT License - see the LICENSE
file for details.