Skip to content

Commit

Permalink
Merge pull request #9547 from microsoft/southworks/fix/jwt-decode-import
Browse files Browse the repository at this point in the history
fix: [#9543] Composer does not recognize valid bearer token
  • Loading branch information
tracyboehrer authored May 9, 2023
2 parents c018e9b + 97f8172 commit 83102c7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

import * as jwt from 'jsonwebtoken';
import { decode } from 'jsonwebtoken';

import {
usGovernmentAuthentication,
Expand Down Expand Up @@ -36,9 +37,9 @@ describe('botFrameworkAuthenticationMiddleware', () => {
mockNext.mockClear();
mockEnd.mockClear();
mockStatus.mockClear();
(jwt.decode as jest.Mock).mockClear();
(decode as jest.Mock).mockClear();
(jwt.verify as jest.Mock).mockClear();
(jwt.decode as jest.Mock).mockImplementation(() => ({
(decode as jest.Mock).mockImplementation(() => ({
header: {
kid: 'someKeyId',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import * as jwt from 'jsonwebtoken';
import * as express from 'express';
import { decode } from 'jsonwebtoken';
import { StatusCodes } from 'http-status-codes';

import { authentication, usGovernmentAuthentication, v31Authentication, v32Authentication } from '../utils/constants';
Expand All @@ -21,7 +22,7 @@ export const createBotFrameworkAuthenticationMiddleware = () => {
}

const [authMethod, token] = authorization.trim().split(' ');
const decoded: any = /^bearer$/i.test(authMethod) && token && jwt.decode(token, { complete: true });
const decoded: any = /^bearer$/i.test(authMethod) && token && decode(token, { complete: true });

if (!decoded) {
res.status(StatusCodes.UNAUTHORIZED).end();
Expand Down

0 comments on commit 83102c7

Please sign in to comment.