Skip to content

Commit f326b85

Browse files
authored
fix(provider): adding tokens to verify type for azure (#92)
BREAKING CHANGE: changed the verify function signature GH-91
1 parent d3516a1 commit f326b85

File tree

5 files changed

+41
-5
lines changed

5 files changed

+41
-5
lines changed

src/__tests__/fixtures/providers/azuread-auth.provider.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export class BearerTokenVerifyProvider
1111

1212
value(): VerifyFunction.AzureADAuthFn {
1313
return async (
14+
accessToken: string,
15+
refreshToken: string,
1416
profile: AzureADAuthStrategy.IProfile,
1517
done: AzureADAuthStrategy.VerifyCallback,
1618
req?: Request,

src/__tests__/unit/passport-azure-ad/azuread-auth-strategy.unit.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ async function getStrategy() {
7070
}
7171

7272
//returning a user
73-
function verifierBearer(profile: IProfile): Promise<IAuthUser | null> {
73+
function verifierBearer(
74+
accessToken: string,
75+
refreshToken: string,
76+
profile: IProfile,
77+
): Promise<IAuthUser | null> {
7478
const userToPass: IAuthUser = {
7579
id: 1,
7680
username: 'xyz',

src/strategies/passport/passport-azure-ad/azuread-auth-strategy-factory-provider.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,27 @@ export class AzureADAuthStrategyFactoryProvider
4242
options,
4343

4444
// eslint-disable-next-line @typescript-eslint/no-misused-promises
45-
async (req: Request, profile: IProfile, done: VerifyCallback) => {
45+
async (
46+
req: Request,
47+
iss: string,
48+
sub: string,
49+
profile: IProfile,
50+
accessToken: string,
51+
refreshToken: string,
52+
done: VerifyCallback,
53+
) => {
4654
if (!profile.oid) {
4755
return done(new Error('No oid found'), null);
4856
}
4957

5058
try {
51-
const user = await verifyFn(profile, done, req);
59+
const user = await verifyFn(
60+
accessToken,
61+
refreshToken,
62+
profile,
63+
done,
64+
req,
65+
);
5266
if (!user) {
5367
throw new HttpErrors.Unauthorized(
5468
AuthErrorKeys.InvalidCredentials,
@@ -65,13 +79,25 @@ export class AzureADAuthStrategyFactoryProvider
6579
options,
6680

6781
// eslint-disable-next-line @typescript-eslint/no-misused-promises
68-
async (profile: IProfile, done: VerifyCallback) => {
82+
async (
83+
iss: string,
84+
sub: string,
85+
profile: IProfile,
86+
accessToken: string,
87+
refreshToken: string,
88+
done: VerifyCallback,
89+
) => {
6990
if (!profile.oid) {
7091
return done(new Error('No oid found'), null);
7192
}
7293

7394
try {
74-
const user = await verifyFn(profile, done);
95+
const user = await verifyFn(
96+
accessToken,
97+
refreshToken,
98+
profile,
99+
done,
100+
);
75101
if (!user) {
76102
throw new HttpErrors.Unauthorized(
77103
AuthErrorKeys.InvalidCredentials,

src/strategies/passport/passport-azure-ad/azuread-auth-verify.provider.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export class AzureADAuthVerifyProvider
1616

1717
value(): VerifyFunction.AzureADAuthFn {
1818
return async (
19+
accessToken: string,
20+
refreshToken: string,
1921
profile: AzureADStrategy.IProfile,
2022
done: AzureADStrategy.VerifyCallback,
2123
req?: Request,

src/strategies/types/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ export namespace VerifyFunction {
5656

5757
export interface AzureADAuthFn<T = IAuthUser> extends GenericAuthFn<T> {
5858
(
59+
accessToken: string,
60+
refreshToken: string,
5961
profile: AzureADStrategy.IProfile,
6062
done: AzureADStrategy.VerifyCallback,
6163
req?: Request,

0 commit comments

Comments
 (0)