Skip to content

Commit c80468a

Browse files
committed
chore: move issuer to example app config
1 parent 124506e commit c80468a

File tree

5 files changed

+11
-6
lines changed

5 files changed

+11
-6
lines changed

example/src/contentpassConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ import type { Config } from 'react-native-contentpass';
33
export const contentpassConfig: Config = {
44
propertyId: 'cc3fc4ad-cbe5-4d09-bf85-a49796603b19',
55
redirectUrl: 'de.contentpass.demo://oauth',
6+
issuer: 'https://my.contentpass.dev',
67
};

expoExample/src/contentpassConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ import type { Config } from 'react-native-contentpass';
33
export const contentpassConfig: Config = {
44
propertyId: 'cc3fc4ad-cbe5-4d09-bf85-a49796603b19',
55
redirectUrl: 'de.contentpass.demo://oauth',
6+
issuer: 'https://my.contentpass.dev',
67
};

src/index.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { authorize, type AuthorizeResult } from 'react-native-app-auth';
2-
import { ISSUER, SCOPES } from './oidcConsts';
2+
import { SCOPES } from './oidcConsts';
33
import OidcAuthStateStorage from './OidcAuthStateStorage';
44
import parseContentpassToken from './utils/parseContentpassToken';
55
import fetchContentpassToken from './utils/fetchContentpassToken';
66

77
export type Config = {
88
propertyId: string;
99
redirectUrl: string;
10+
issuer: string;
1011
};
1112

1213
export enum State {
@@ -49,7 +50,7 @@ export class Contentpass {
4950
result = await authorize({
5051
clientId: this.config.propertyId,
5152
redirectUrl: this.config.redirectUrl,
52-
issuer: ISSUER,
53+
issuer: this.config.issuer,
5354
scopes: SCOPES,
5455
additionalParameters: {
5556
cp_route: 'login',
@@ -72,8 +73,9 @@ export class Contentpass {
7273

7374
try {
7475
const contentpassToken = await fetchContentpassToken({
75-
idToken: result.idToken,
76+
issuer: this.config.issuer,
7677
propertyId: this.config.propertyId,
78+
idToken: result.idToken,
7779
});
7880
const hasValidSubscription = this.validateSubscription(contentpassToken);
7981

src/oidcConsts.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
export const SCOPES = ['openid', 'offline_access', 'contentpass'];
2-
export const ISSUER = 'https://my.contentpass.net';
3-
export const TOKEN_ENDPOINT = `${ISSUER}/auth/oidc/token`;
2+
export const TOKEN_ENDPOINT = `/auth/oidc/token`;

src/utils/fetchContentpassToken.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import { TOKEN_ENDPOINT } from '../oidcConsts';
33
export default async function fetchContentpassToken({
44
idToken,
55
propertyId,
6+
issuer,
67
}: {
78
idToken: string;
89
propertyId: string;
10+
issuer: string;
911
}) {
10-
const tokenEndpointResponse = await fetch(TOKEN_ENDPOINT, {
12+
const tokenEndpointResponse = await fetch(`${issuer}${TOKEN_ENDPOINT}`, {
1113
method: 'POST',
1214
headers: {
1315
'Content-Type': 'application/x-www-form-urlencoded',

0 commit comments

Comments
 (0)