Wocha Docs

Angular SDK

Angular service, guard, and callback component for Wocha SPA authentication.

@wocha/angular provides an Angular service, route guard, and callback component for Wocha authentication in single-page applications. Implements OAuth 2.0 authorisation code with PKCE.

Installation

pnpm add @wocha/angular
Or scaffold with the CLI
npx @wocha/cli init --framework react-spa

Peer dependencies: Angular 17+, @angular/router, RxJS 7+.

Setup

import { WochaAuthModule } from "@wocha/angular";
 
WochaAuthModule.forRoot({
  issuer: "https://my-tenant.auth.wocha.ai",
  clientId: "your-client-id",
  redirectUri: window.location.origin + "/callback",
});

Routes

import { GreetCallbackComponent, wochaAuthGuard } from "@wocha/angular";
 
export const routes = [
  { path: "callback", component: GreetCallbackComponent },
  {
    path: "dashboard",
    canActivate: [wochaAuthGuard],
    loadComponent: () => import("./dashboard"),
  },
];

WochaAuthService

import { inject } from "@angular/core";
import { WochaAuthService } from "@wocha/angular";
 
export class HeaderComponent {
  private auth = inject(WochaAuthService);
 
  user$ = this.auth.user$;
  isAuthenticated$ = this.auth.isAuthenticated$;
 
  ngOnInit() {
    this.auth.restore();
  }
 
  signIn() {
    this.auth.signIn();
  }
 
  signOut() {
    this.auth.signOut();
  }
}

Configuration

FieldRequiredDescription
issuerYesOIDC issuer URL
clientIdYesOAuth client ID
redirectUriNoDefaults to {origin}/callback
scopesNoDefault: openid profile email offline_access
platformApiUrlNoFor permission checks

Learn more

On this page