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
12 changes: 12 additions & 0 deletions .changeset/true-bats-read.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"fayda": patch
---

Add optional `scopes` parameter to `FaydaOptions` interface for customizable OAuth scopes.

- **New Feature**: Added `scopes?: string[]` parameter to allow custom OAuth scope configuration
- **Default Behavior**: Maintains existing default scopes `["openid", "profile", "email"]` when not provided
- **Backward Compatible**: Existing implementations continue to work without changes
- **Usage**: Pass custom scopes like `scopes: ["openid", "profile", "email", "address"]` for additional permissions

This enables flexible authentication by allowing users to request specific OAuth scopes based on their application needs.
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ const DISCOVERY_URL =
const USER_INFO_URL = "https://esignet.ida.fayda.et/v1/esignet/oidc/userinfo";
const TOKEN_ENDPOINT = "https://esignet.ida.fayda.et/v1/esignet/oauth/v2/token";

// Default scopes for Fayda authentication
const DEFAULT_SCOPES = ["openid", "profile", "email"];

export interface FaydaOptions {
clientId: string;
privateKey: string;
redirectUrl?: string;
scopes?: string[];
}

type Fayda = Promise<ReturnType<typeof genericOAuth>>;
Expand All @@ -20,6 +24,7 @@ export const fayda = async ({
clientId,
privateKey,
redirectUrl,
scopes,
}: FaydaOptions): Fayda => {
return genericOAuth({
config: [
Expand All @@ -37,7 +42,7 @@ export const fayda = async ({
"urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
},

scopes: ["openid", "profile", "email"],
scopes: scopes?.length ? scopes : DEFAULT_SCOPES,

async getUserInfo(tokens) {
const userInfo = await betterFetch<Blob>(USER_INFO_URL, {
Expand Down