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
3 changes: 3 additions & 0 deletions packages/example/src/authentication-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
Log,
// CognitoProvider as OpenIDAuthenticationProvider,
// useCongito as useAuth,
Auth0Provider as OpenIDAuthenticationProvider,
Expand Down Expand Up @@ -59,6 +60,8 @@
return (
<OpenIDAuthenticationProvider
{...OpenIDAuthenticationProviderProps}
logger={console}
logLevel={Log.DEBUG}
onAccessTokenChanged={handleAccessTokenChange}
>
<AccessTokenProvider accessToken={accessToken}>
Expand All @@ -68,9 +71,9 @@
);
};

export const useAccessToken = (): Token | undefined => {

Check warning on line 74 in packages/example/src/authentication-provider.tsx

View workflow job for this annotation

GitHub Actions / build

Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components
const token = useContext(AccessTokenContext);
return token;
};

export { useAuth, withAuthenticationRequired };

Check warning on line 79 in packages/example/src/authentication-provider.tsx

View workflow job for this annotation

GitHub Actions / build

Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components

Check warning on line 79 in packages/example/src/authentication-provider.tsx

View workflow job for this annotation

GitHub Actions / build

Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components
57 changes: 56 additions & 1 deletion packages/oidc-provider/src/__tests__/auth0-provider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,17 @@ import * as utils from "../utils";
vi.mock("oidc-client-ts", () => ({
UserManager: vi.fn(),
WebStorageStateStore: vi.fn(),
Log: {
setLogger: vi.fn(),
setLevel: vi.fn(),
NONE: 0,
ERROR: 1,
WARN: 2,
INFO: 3,
DEBUG: 4,
},
InMemoryWebStorage: class InMemoryWebStorage {
private storage: Map<string, string> = new Map();
private readonly storage: Map<string, string> = new Map();
get length() {
return this.storage.size;
}
Expand Down Expand Up @@ -643,6 +652,52 @@ describe("Auth0Provider", () => {
});
});

describe("Logger Configuration", () => {
it("should pass logger prop to OIDCProvider", async () => {
const { Log } = await import("oidc-client-ts");
const mockLogger = {
debug: vi.fn(),
info: vi.fn(),
warn: vi.fn(),
error: vi.fn(),
};

render(
<Auth0Provider
domain="test-tenant.auth0.com"
clientId="test-client-id"
redirectUri="https://example.com/callback"
logger={mockLogger}
>
<div>Test</div>
</Auth0Provider>,
);

await waitFor(() => {
expect(Log.setLogger).toHaveBeenCalledWith(mockLogger);
});
});

it("should pass logLevel prop to OIDCProvider", async () => {
const { Log } = await import("oidc-client-ts");

render(
<Auth0Provider
domain="test-tenant.auth0.com"
clientId="test-client-id"
redirectUri="https://example.com/callback"
logLevel={Log.DEBUG}
>
<div>Test</div>
</Auth0Provider>,
);

await waitFor(() => {
expect(Log.setLevel).toHaveBeenCalledWith(Log.DEBUG);
});
});
});

describe("Integration with OIDCProvider", () => {
it("should pass through additional OIDC provider props", async () => {
render(
Expand Down
57 changes: 57 additions & 0 deletions packages/oidc-provider/src/__tests__/azure-provider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ import * as utils from "../utils";
vi.mock("oidc-client-ts", () => ({
UserManager: vi.fn(),
WebStorageStateStore: vi.fn(),
Log: {
setLogger: vi.fn(),
setLevel: vi.fn(),
NONE: 0,
ERROR: 1,
WARN: 2,
INFO: 3,
DEBUG: 4,
},
InMemoryWebStorage: class InMemoryWebStorage {
private readonly storage: Map<string, string> = new Map();
get length() {
Expand Down Expand Up @@ -618,6 +627,54 @@ describe("AzureProvider", () => {
});
});

describe("Logger Configuration", () => {
it("should pass logger prop to OIDCProvider", async () => {
const { Log } = await import("oidc-client-ts");
const mockLogger = {
debug: vi.fn(),
info: vi.fn(),
warn: vi.fn(),
error: vi.fn(),
};

render(
<AzureProvider
domain="test-tenant.b2clogin.com"
clientId="test-client-id"
redirectUri="https://example.com/callback"
policy="B2C_1_signin"
logger={mockLogger}
>
<div>Test</div>
</AzureProvider>,
);

await waitFor(() => {
expect(Log.setLogger).toHaveBeenCalledWith(mockLogger);
});
});

it("should pass logLevel prop to OIDCProvider", async () => {
const { Log } = await import("oidc-client-ts");

render(
<AzureProvider
domain="test-tenant.b2clogin.com"
clientId="test-client-id"
redirectUri="https://example.com/callback"
policy="B2C_1_signin"
logLevel={Log.WARN}
>
<div>Test</div>
</AzureProvider>,
);

await waitFor(() => {
expect(Log.setLevel).toHaveBeenCalledWith(Log.WARN);
});
});
});

describe("Integration with OIDCProvider", () => {
it("should pass through additional OIDC provider props", async () => {
render(
Expand Down
55 changes: 55 additions & 0 deletions packages/oidc-provider/src/__tests__/cognito-provider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ import * as utils from "../utils";
vi.mock("oidc-client-ts", () => ({
UserManager: vi.fn(),
WebStorageStateStore: vi.fn(),
Log: {
setLogger: vi.fn(),
setLevel: vi.fn(),
NONE: 0,
ERROR: 1,
WARN: 2,
INFO: 3,
DEBUG: 4,
},
InMemoryWebStorage: class InMemoryWebStorage {
private readonly storage: Map<string, string> = new Map();
get length() {
Expand Down Expand Up @@ -594,6 +603,52 @@ describe("CognitoProvider", () => {
});
});

describe("Logger Configuration", () => {
it("should pass logger prop to OIDCProvider", async () => {
const { Log } = await import("oidc-client-ts");
const mockLogger = {
debug: vi.fn(),
info: vi.fn(),
warn: vi.fn(),
error: vi.fn(),
};

render(
<CognitoProvider
domain="test-domain.auth.us-east-1.amazoncognito.com"
clientId="test-client-id"
redirectUri="https://example.com/callback"
logger={mockLogger}
>
<div>Test</div>
</CognitoProvider>,
);

await waitFor(() => {
expect(Log.setLogger).toHaveBeenCalledWith(mockLogger);
});
});

it("should pass logLevel prop to OIDCProvider", async () => {
const { Log } = await import("oidc-client-ts");

render(
<CognitoProvider
domain="test-domain.auth.us-east-1.amazoncognito.com"
clientId="test-client-id"
redirectUri="https://example.com/callback"
logLevel={Log.INFO}
>
<div>Test</div>
</CognitoProvider>,
);

await waitFor(() => {
expect(Log.setLevel).toHaveBeenCalledWith(Log.INFO);
});
});
});

describe("Integration with OIDCProvider", () => {
it("should pass through additional OIDC provider props", async () => {
render(
Expand Down
Loading