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
1 change: 1 addition & 0 deletions example/src/contentpassConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};
1 change: 1 addition & 0 deletions expoExample/src/contentpassConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};
8 changes: 5 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
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';

export type Config = {
propertyId: string;
redirectUrl: string;
issuer: string;
};

export enum State {
Expand Down Expand Up @@ -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',
Expand All @@ -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);

Expand Down
3 changes: 1 addition & 2 deletions src/oidcConsts.ts
Original file line number Diff line number Diff line change
@@ -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`;
4 changes: 3 additions & 1 deletion src/utils/fetchContentpassToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down