Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/angular/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oidc-js-angular",
"version": "1.0.8",
"version": "1.1.0",
"description": "Simple OIDC authentication for Angular. Signals, DI, and route guards with zero dependencies.",
"type": "module",
"main": "./dist/index.cjs",
Expand Down
8 changes: 4 additions & 4 deletions packages/angular/src/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,16 @@ export class AuthService {
*
* @throws Error if no refresh token is available.
*/
async refresh(): Promise<void> {
await this.client.refresh();
async refresh() {
return this.client.refresh();
}

/**
* Fetches the user's profile from the userinfo endpoint using the current access token.
*
* @throws Error if no access token is available.
*/
async fetchProfile(): Promise<void> {
await this.client.fetchProfile();
async fetchProfile() {
return this.client.fetchProfile();
}
}
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oidc-js",
"version": "1.0.8",
"version": "1.1.0",
"description": "Simple OIDC authentication for JavaScript. Drop-in client with login, logout, token refresh, and zero dependencies.",
"type": "module",
"main": "./dist/index.cjs",
Expand Down
11 changes: 7 additions & 4 deletions packages/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class OidcClient {
private discovery: OidcDiscovery | null = null;
private subscribers = new Set<Subscriber>();
private abortController: AbortController | null = null;
private refreshPromise: Promise<void> | null = null;
private refreshPromise: Promise<AuthTokens> | null = null;

private _state: AuthState = {
user: null,
Expand Down Expand Up @@ -243,7 +243,7 @@ export class OidcClient {
*
* @throws Error if no refresh token is available or discovery has not been fetched.
*/
async refresh(): Promise<void> {
async refresh(): Promise<AuthTokens> {
if (this.refreshPromise) {
return this.refreshPromise;
}
Expand All @@ -255,7 +255,7 @@ export class OidcClient {
return this.refreshPromise;
}

private async refreshInternal(): Promise<void> {
private async refreshInternal(): Promise<AuthTokens> {
const refreshToken = this._state.tokens.refresh;

if (!this.discovery || !refreshToken) {
Expand Down Expand Up @@ -289,6 +289,8 @@ export class OidcClient {
isAuthenticated: true,
error: null,
});

return newTokens;
}

/**
Expand All @@ -298,7 +300,7 @@ export class OidcClient {
*
* @throws Error if no access token is available or discovery has not been fetched.
*/
async fetchProfile(): Promise<void> {
async fetchProfile(): Promise<OidcUser | null> {
if (!this.discovery || !this._state.tokens.access) {
throw new Error("No access token available");
}
Expand All @@ -307,6 +309,7 @@ export class OidcClient {
if (this._state.user) {
this.setState({ user: { ...this._state.user, profile } });
}
return profile;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oidc-js-core",
"version": "1.0.8",
"version": "1.1.0",
"description": "Zero-dependency OIDC/OAuth 2.0 functions for JavaScript. Pure, functional, works everywhere.",
"type": "module",
"main": "./dist/index.cjs",
Expand Down
2 changes: 1 addition & 1 deletion packages/kasper/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oidc-js-kasper",
"version": "1.0.8",
"version": "1.1.0",
"description": "Simple OIDC authentication for Kasper.js. Signals, components, and auth guards with zero dependencies.",
"type": "module",
"main": "./dist/index.cjs",
Expand Down
5 changes: 3 additions & 2 deletions packages/kasper/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Signal } from "kasper-js";
import type { OidcConfig } from "oidc-js-core";
import type { AuthUser, AuthTokens, LoginOptions } from "oidc-js";
import type { OidcUser } from "oidc-js-core";

export type { IdTokenClaims, AuthUser, AuthTokens, LoginOptions } from "oidc-js";
export type { Signal } from "kasper-js";
Expand All @@ -12,9 +13,9 @@ export interface AuthActions {
/** Logs the user out and redirects to the post-logout URI. */
logout: () => void;
/** Refreshes the access token using the refresh token. */
refresh: () => Promise<void>;
refresh: () => Promise<AuthTokens>;
/** Fetches the user's profile from the userinfo endpoint. */
fetchProfile: () => Promise<void>;
fetchProfile: () => Promise<OidcUser | null>;
}

/** Value returned by {@link useAuth}. All state properties are Kasper signals. */
Expand Down
2 changes: 1 addition & 1 deletion packages/lit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oidc-js-lit",
"version": "1.0.8",
"version": "1.1.0",
"description": "Simple OIDC authentication for Lit. Reactive controllers for login, logout, and token refresh with zero dependencies.",
"type": "module",
"main": "./dist/index.cjs",
Expand Down
9 changes: 5 additions & 4 deletions packages/lit/src/auth-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,17 @@ export class AuthController implements ReactiveController {
*
* @throws Error if no refresh token is available or discovery has not been fetched.
*/
async refresh(): Promise<void> {
await this.client?.refresh();
async refresh() {
const result = await this.client?.refresh();
return result ?? { access: null, id: null, refresh: null, expiresAt: null };
}

/**
* Fetches the user's profile from the userinfo endpoint using the current access token.
*
* @throws Error if no access token is available or discovery has not been fetched.
*/
async fetchProfile(): Promise<void> {
await this.client?.fetchProfile();
async fetchProfile() {
return (await this.client?.fetchProfile()) ?? null;
}
}
7 changes: 4 additions & 3 deletions packages/lit/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import type { OidcConfig } from "oidc-js-core";

export type { IdTokenClaims, AuthUser, AuthTokens, LoginOptions } from "oidc-js";

import type { LoginOptions } from "oidc-js";
import type { AuthTokens, LoginOptions } from "oidc-js";
import type { OidcUser } from "oidc-js-core";

/**
* Actions available on the {@link AuthController} for triggering authentication operations.
Expand All @@ -13,9 +14,9 @@ export interface AuthActions {
/** Logs the user out and redirects to the OP's end-session endpoint. */
logout: () => void;
/** Uses the stored refresh token to obtain new tokens. */
refresh: () => Promise<void>;
refresh: () => Promise<AuthTokens>;
/** Fetches the user's profile from the userinfo endpoint. */
fetchProfile: () => Promise<void>;
fetchProfile: () => Promise<OidcUser | null>;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/preact/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oidc-js-preact",
"version": "1.0.8",
"version": "1.1.0",
"description": "Simple OIDC authentication for Preact. Hooks, provider, and auth guards with zero dependencies.",
"type": "module",
"main": "./dist/index.cjs",
Expand Down
5 changes: 3 additions & 2 deletions packages/preact/src/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,12 @@ export function AuthProvider({
}, []);

const refresh = useCallback(async () => {
await clientRef.current?.refresh();
const result = await clientRef.current?.refresh();
return result ?? { access: null, id: null, refresh: null, expiresAt: null };
}, []);

const doFetchProfile = useCallback(async () => {
await clientRef.current?.fetchProfile();
return (await clientRef.current?.fetchProfile()) ?? null;
}, []);

const actions = useMemo(
Expand Down
5 changes: 3 additions & 2 deletions packages/preact/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { OidcConfig } from "oidc-js-core";
export type { IdTokenClaims, AuthUser, AuthTokens, LoginOptions } from "oidc-js";

import type { AuthUser, AuthTokens, LoginOptions } from "oidc-js";
import type { OidcUser } from "oidc-js-core";

/** Actions available for controlling the authentication lifecycle. */
export interface AuthActions {
Expand All @@ -11,9 +12,9 @@ export interface AuthActions {
/** Logs the user out and optionally redirects to the OP's end-session endpoint. */
logout: () => void;
/** Refreshes the access token using the stored refresh token. */
refresh: () => Promise<void>;
refresh: () => Promise<AuthTokens>;
/** Fetches the user's profile from the userinfo endpoint. */
fetchProfile: () => Promise<void>;
fetchProfile: () => Promise<OidcUser | null>;
}

/** The value provided by {@link AuthProvider} and consumed by {@link useAuth}. */
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oidc-js-react",
"version": "1.0.8",
"version": "1.1.0",
"description": "Simple OIDC authentication for React. Provider, hooks, and route guards with zero dependencies.",
"type": "module",
"main": "./dist/index.cjs",
Expand Down
7 changes: 4 additions & 3 deletions packages/react/src/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,12 @@ export function AuthProvider({
}, []);

const refresh = useCallback(async () => {
await clientRef.current?.refresh();
const result = await clientRef.current?.refresh();
return result ?? { access: null, id: null, refresh: null, expiresAt: null };
}, []);

const doFetchProfile = useCallback(async () => {
await clientRef.current?.fetchProfile();
return (await clientRef.current?.fetchProfile()) ?? null;
}, []);

const actions = useMemo(
Expand All @@ -93,7 +94,7 @@ export function AuthProvider({
);

const value: AuthContextValue = useMemo(
() => ({ config, ...state, actions }),
() => ({ config, client: clientRef.current!, ...state, actions }),
[config, state, actions],
);

Expand Down
1 change: 1 addition & 0 deletions packages/react/src/tests/auth-required.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function makeActions(overrides: Partial<AuthContextValue["actions"]> = {}) {
function makeAuth(overrides: Partial<AuthContextValue> = {}): AuthContextValue {
return {
config: { issuer: "https://auth.example.com", clientId: "app" },
client: {} as AuthContextValue["client"],
user: null,
isAuthenticated: false,
isLoading: false,
Expand Down
8 changes: 5 additions & 3 deletions packages/react/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ import type { OidcConfig } from "oidc-js-core";

export type { IdTokenClaims, AuthUser, AuthTokens, LoginOptions } from "oidc-js";

import type { AuthUser, AuthTokens, LoginOptions } from "oidc-js";
import type { OidcClient, AuthUser, AuthTokens, LoginOptions } from "oidc-js";
import type { OidcUser } from "oidc-js-core";

export interface AuthActions {
login: (options?: LoginOptions) => void;
logout: () => void;
refresh: () => Promise<void>;
fetchProfile: () => Promise<void>;
refresh: () => Promise<AuthTokens>;
fetchProfile: () => Promise<OidcUser | null>;
}

export interface AuthContextValue {
config: OidcConfig;
client: OidcClient;
user: AuthUser | null;
isAuthenticated: boolean;
isLoading: boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/solid/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oidc-js-solid",
"version": "1.0.8",
"version": "1.1.0",
"description": "Simple OIDC authentication for SolidJS. Signals, context, and auth guards with zero dependencies.",
"type": "module",
"main": "./dist/index.cjs",
Expand Down
5 changes: 3 additions & 2 deletions packages/solid/src/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,12 @@ export const AuthProvider: ParentComponent<AuthProviderProps> = (props) => {
};

const refresh = async () => {
await client?.refresh();
const result = await client?.refresh();
return result ?? { access: null, id: null, refresh: null, expiresAt: null };
};

const doFetchProfile = async () => {
await client?.fetchProfile();
return (await client?.fetchProfile()) ?? null;
};

const actions = { login, logout, refresh, fetchProfile: doFetchProfile };
Expand Down
5 changes: 3 additions & 2 deletions packages/solid/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { OidcConfig } from "oidc-js-core";
export type { IdTokenClaims, AuthUser, AuthTokens, LoginOptions } from "oidc-js";

import type { AuthUser, AuthTokens, LoginOptions } from "oidc-js";
import type { OidcUser } from "oidc-js-core";

/**
* Actions available for controlling authentication flow.
Expand All @@ -15,9 +16,9 @@ export interface AuthActions {
/** Logs out the current user and clears auth state. */
logout: () => void;
/** Refreshes the access token using the stored refresh token. */
refresh: () => Promise<void>;
refresh: () => Promise<AuthTokens>;
/** Fetches the user's profile from the userinfo endpoint. */
fetchProfile: () => Promise<void>;
fetchProfile: () => Promise<OidcUser | null>;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oidc-js-svelte",
"version": "1.0.8",
"version": "1.1.0",
"description": "Simple OIDC authentication for Svelte 5. Context, runes, and auth guards with zero dependencies.",
"type": "module",
"svelte": "./dist/index.js",
Expand Down
5 changes: 3 additions & 2 deletions packages/svelte/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { OidcConfig } from "oidc-js-core";
export type { IdTokenClaims, AuthUser, AuthTokens, LoginOptions } from "oidc-js";

import type { AuthUser, AuthTokens, LoginOptions } from "oidc-js";
import type { OidcUser } from "oidc-js-core";

/** Actions available to interact with the OIDC authentication flow. */
export interface AuthActions {
Expand All @@ -11,9 +12,9 @@ export interface AuthActions {
/** Logs the user out and redirects to the end-session endpoint. */
logout: () => void;
/** Refreshes the access token using the stored refresh token. */
refresh: () => Promise<void>;
refresh: () => Promise<AuthTokens>;
/** Fetches the user's profile from the userinfo endpoint. */
fetchProfile: () => Promise<void>;
fetchProfile: () => Promise<OidcUser | null>;
}

/** Reactive authentication context value provided by {@link AuthProvider}. */
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oidc-js-vue",
"version": "1.0.8",
"version": "1.1.0",
"description": "Simple OIDC authentication for Vue. Plugin, composables, and navigation guards with zero dependencies.",
"type": "module",
"main": "./dist/index.cjs",
Expand Down
4 changes: 2 additions & 2 deletions packages/vue/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ export const oidcPlugin = {
};

const refresh = async () => {
await client.refresh();
return client.refresh();
};

const doFetchProfile = async () => {
await client.fetchProfile();
return client.fetchProfile();
};

const actions: AuthActions = {
Expand Down
5 changes: 3 additions & 2 deletions packages/vue/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { OidcConfig } from "oidc-js-core";
export type { IdTokenClaims, AuthUser, AuthTokens, LoginOptions } from "oidc-js";

import type { AuthUser, AuthTokens, LoginOptions } from "oidc-js";
import type { OidcUser } from "oidc-js-core";

/**
* Actions available for authentication operations.
Expand All @@ -16,9 +17,9 @@ export interface AuthActions {
/** Logs the user out and redirects to the OP's end-session endpoint. */
logout: () => void;
/** Uses the stored refresh token to obtain a new set of tokens. */
refresh: () => Promise<void>;
refresh: () => Promise<AuthTokens>;
/** Fetches the user's profile from the userinfo endpoint. */
fetchProfile: () => Promise<void>;
fetchProfile: () => Promise<OidcUser | null>;
}

/**
Expand Down
Loading