diff --git a/example/src/contentpassConfig.ts b/example/src/contentpassConfig.ts index af28eb7..7347e66 100644 --- a/example/src/contentpassConfig.ts +++ b/example/src/contentpassConfig.ts @@ -3,4 +3,5 @@ import type { Config } from 'react-native-contentpass'; export const contentpassConfig: Config = { propertyId: 'cc3fc4ad-cbe5-4d09-bf85-a49796603b19', redirectUrl: 'de.contentpass.demo://oauth', + issuer: 'https://my.contentpass.dev', }; diff --git a/expoExample/src/contentpassConfig.ts b/expoExample/src/contentpassConfig.ts index af28eb7..7347e66 100644 --- a/expoExample/src/contentpassConfig.ts +++ b/expoExample/src/contentpassConfig.ts @@ -3,4 +3,5 @@ import type { Config } from 'react-native-contentpass'; export const contentpassConfig: Config = { propertyId: 'cc3fc4ad-cbe5-4d09-bf85-a49796603b19', redirectUrl: 'de.contentpass.demo://oauth', + issuer: 'https://my.contentpass.dev', }; diff --git a/src/index.tsx b/src/index.tsx index f974bee..5aac597 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,5 +1,5 @@ import { authorize, type AuthorizeResult } from 'react-native-app-auth'; -import { ISSUER, SCOPES } from './oidcConsts'; +import { SCOPES } from './oidcConsts'; import OidcAuthStateStorage from './OidcAuthStateStorage'; import parseContentpassToken from './utils/parseContentpassToken'; import fetchContentpassToken from './utils/fetchContentpassToken'; @@ -7,6 +7,7 @@ import fetchContentpassToken from './utils/fetchContentpassToken'; export type Config = { propertyId: string; redirectUrl: string; + issuer: string; }; export enum State { @@ -49,7 +50,7 @@ export class Contentpass { result = await authorize({ clientId: this.config.propertyId, redirectUrl: this.config.redirectUrl, - issuer: ISSUER, + issuer: this.config.issuer, scopes: SCOPES, additionalParameters: { cp_route: 'login', @@ -72,8 +73,9 @@ export class Contentpass { try { const contentpassToken = await fetchContentpassToken({ - idToken: result.idToken, + issuer: this.config.issuer, propertyId: this.config.propertyId, + idToken: result.idToken, }); const hasValidSubscription = this.validateSubscription(contentpassToken); diff --git a/src/oidcConsts.ts b/src/oidcConsts.ts index db7b7f1..6adb528 100644 --- a/src/oidcConsts.ts +++ b/src/oidcConsts.ts @@ -1,3 +1,2 @@ export const SCOPES = ['openid', 'offline_access', 'contentpass']; -export const ISSUER = 'https://my.contentpass.net'; -export const TOKEN_ENDPOINT = `${ISSUER}/auth/oidc/token`; +export const TOKEN_ENDPOINT = `/auth/oidc/token`; diff --git a/src/utils/fetchContentpassToken.ts b/src/utils/fetchContentpassToken.ts index 4cd7b3e..34b72e0 100644 --- a/src/utils/fetchContentpassToken.ts +++ b/src/utils/fetchContentpassToken.ts @@ -3,11 +3,13 @@ import { TOKEN_ENDPOINT } from '../oidcConsts'; export default async function fetchContentpassToken({ idToken, propertyId, + issuer, }: { idToken: string; propertyId: string; + issuer: string; }) { - const tokenEndpointResponse = await fetch(TOKEN_ENDPOINT, { + const tokenEndpointResponse = await fetch(`${issuer}${TOKEN_ENDPOINT}`, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded',