oidc-client-rx
Version:
ReactiveX enhanced OIDC and OAuth2 protocol support for browser-based JavaScript applications
65 lines (51 loc) • 2.1 kB
Markdown
<h1 align="center">
<img src="./assets/logo-512.png" height="150" alt="logo">
<div style="color: #232848; font-weight: 700;">OIDC-CLIENT-RX</div>
<div align="center">
<img src="https://img.shields.io/github/actions/workflow/status/aitiotekt/oidc-client-rx/ci.yml" alt="build-status" />
<img src="https://img.shields.io/npm/v/oidc-client-rx?tag=latest&label=npm&color=blue" alt="npm-version" />
</div>
</h1>
<p align="center">ReactiveX enhanced OIDC and OAuth2 protocol support for browser-based JavaScript applications.</p>
## Quick Start
Choose a reflection lib such as `@abraham/reflection` or `reflect-metadata` or `core-js/es7/reflect`, then install:
```shell
pnpm add oidc-client-rx injection-js reflect-metadata
# or npm
npm install oidc-client-rx injection-js reflect-metadata
# or yarn
yarn add oidc-client-rx injection-js reflect-metadata
```
```typescript
import 'reflect-metadata'; // or '@abraham/reflection' | 'core-js/es7/reflect'
import { type Injector, ReflectiveInjector } from 'injection-js';
import { LogLevel, OidcSecurityService, provideAuth, withDefaultFeatures } from 'oidc-client-rx';
const injector = ReflectiveInjector.resolveAndCreate(
provideAuth(
{
config: {
authority: '<your-authority>',
redirectUrl: `${window.location.origin}/auth/callback`,
postLogoutRedirectUri: window.location.origin,
clientId: '<your-client-id>',
scope: 'openid profile email offline_access',
responseType: 'code',
silentRenew: true,
useRefreshToken: true,
logLevel: LogLevel.Debug,
...
},
},
withDefaultFeatures()
)
) as Injector;
const oidcSecurityService = injector.get(OidcSecurityService);
oidcSecurityService.checkAuth().subscribe((result) => {
console.debug('checkAuth result: ', result);
});
const isAuthenticated$ = oidcSecurityService.isAuthenticated$;
```
### More Examples
- [React + TanStack Router](https://github.com/aitiotekt/oidc-client-rx/tree/main/examples/react-tanstack-router)
## License
[MIT](https://choosealicense.com/licenses/mit/)