UNPKG

@pvway/alpha-oas

Version:

Professional Angular 20+ OAuth2 authentication and authorization library. Provides robust session and refresh token management, secure HTTP interceptors, strongly-typed user and principal models, and full support for standalone components and signals. Des

128 lines (90 loc) โ€ข 3.85 kB
<!-- AlphaOas - OAuth Authentication Library for Angular --> <h1 align="center">AlphaOas <img src="https://img.shields.io/npm/v/%40pvway%2Falpha-oas.svg" alt="npm version" height="20"> <img src="https://img.shields.io/bundlephobia/min/%40pvway%2Falpha-oas.svg" alt="bundle size" height="20"> <img src="https://img.shields.io/github/license/your-org/alpha-oas.svg" alt="license" height="20"> <img src="https://img.shields.io/github/workflow/status/your-org/alpha-oas/CI" alt="build status" height="20"></h1> <p align="center"> <img src="https://img.shields.io/npm/dm/%40pvway%2Falpha-oas.svg" alt="npm downloads" height="20"> <img src="https://img.shields.io/codecov/c/github/your-org/alpha-oas.svg" alt="coverage" height="20"> <img src="https://img.shields.io/badge/angular-20.3.18%2B-dd0031.svg" alt="Angular" height="20"> </p> --- > <strong>AlphaOas</strong> is a robust, scalable OAuth authentication and authorization library for Angular 20.3.18+ applications. It provides a complete solution for managing user sessions, tokens, and secure HTTP communication, following Angular and TypeScript best practices. --- ## โœจ Features - ๐Ÿ”’ OAuth2 authentication and token management - ๐Ÿง‘โ€๐Ÿ’ป Strongly-typed user and principal models - ๐Ÿ›ก๏ธ HTTP interceptor for secure API requests - ๐Ÿ—๏ธ Session and refresh token lifecycle management - ๐Ÿงฉ Extensible with custom sign-in, refresh, and authorize logic - ๐Ÿท๏ธ Language and client identification headers - ๐Ÿฆพ Designed for standalone Angular libraries - ๐Ÿงช Full unit test coverage ## ๐Ÿš€ Installation ```bash npm install @pvway/alpha-oas uuid ``` > <img src="https://img.shields.io/npm/v/%40pvway%2Falpha-oas.svg" alt="npm version" height="16"> Requires Angular `20.3.18` or above, with Angular peer range `>=20.3.18 <21.0.0`, and RxJS 7+. ## ๐Ÿ“ฆ Usage ### 1. Import and Provide the Service ```typescript import { AlphaOasService } from '@pvway/alpha-oas'; // ProvidedIn: 'root' - no need to add to providers ``` ### 2. Initialize the Service ```typescript service.init( httpClient, getMeUrl, refreshUrl, signInUrl, postErrorLog?, onPrincipalUpdated? ); ``` ### 3. Authenticate and Authorize ```typescript service.signIn(username, password, rememberMe).subscribe(...); service.refresh().subscribe(...); service.getMe().subscribe(...); service.authorize(httpRequest).subscribe(...); ``` ### 4. Use the HTTP Interceptor ```typescript import { HTTP_INTERCEPTORS } from '@angular/common/http'; import { AlphaOasInterceptor } from '@pvway/alpha-oas'; @NgModule({ providers: [ { provide: HTTP_INTERCEPTORS, useClass: AlphaOasInterceptor, multi: true } ] }) ``` ## ๐Ÿง‘โ€๐ŸŽ“ API Overview - `AlphaOasService`: Main authentication service - `AlphaOasInterceptor`: HTTP interceptor for secure requests - `AlphaPrincipal`: Tracks authentication state and user - `IAlphaUser`, `IAlphaAuthEnvelop`, `IAlphaPrincipal`: Strongly-typed models - `AlphaSessionData`, `AlphaRefreshData`: Token lifecycle helpers ## ๐Ÿงช Testing Run unit tests with: ```bash ng test AlphaOas ``` ## ๐Ÿ› ๏ธ Building & Publishing Build the library: ```bash ng build AlphaOas ``` Publish to npm: ```bash cd dist/alpha-oas npm publish ``` ## ๐Ÿ“š Documentation - [Angular CLI Reference](https://angular.dev/tools/cli) - [OAuth 2.0 Overview](https://oauth.net/2/) - [RxJS Documentation](https://rxjs.dev/) ## ๐Ÿ“ License This project is licensed under the MIT License. --- <p align="center"> <img src="https://img.shields.io/github/stars/your-org/alpha-oas.svg?style=social" alt="GitHub stars" height="20"> <img src="https://img.shields.io/github/forks/your-org/alpha-oas.svg?style=social" alt="GitHub forks" height="20"> </p>