diff --git a/.changeset/true-bats-read.md b/.changeset/true-bats-read.md new file mode 100644 index 0000000..a815018 --- /dev/null +++ b/.changeset/true-bats-read.md @@ -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. diff --git a/src/index.ts b/src/index.ts index c83b3e0..b01a526 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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>; @@ -20,6 +24,7 @@ export const fayda = async ({ clientId, privateKey, redirectUrl, + scopes, }: FaydaOptions): Fayda => { return genericOAuth({ config: [ @@ -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(USER_INFO_URL, {