forked from backstage/backstage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request backstage#6430 from chicoribas/auth-signin-to-ms-p…
…rovider Implement auth handler and sign-in resolvers for Microsoft auth providers
- Loading branch information
Showing
6 changed files
with
302 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@backstage/plugin-auth-backend': patch | ||
--- | ||
|
||
Add Sign In and Handler resolver for Microsoft provider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
plugins/auth-backend/src/providers/microsoft/provider.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Copyright 2020 The Backstage Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { MicrosoftAuthProvider } from './provider'; | ||
import * as helpers from '../../lib/passport/PassportStrategyHelper'; | ||
import { OAuthResult } from '../../lib/oauth'; | ||
import { getVoidLogger } from '@backstage/backend-common'; | ||
import { TokenIssuer } from '../../identity/types'; | ||
import { CatalogIdentityClient } from '../../lib/catalog'; | ||
|
||
const mockFrameHandler = (jest.spyOn( | ||
helpers, | ||
'executeFrameHandlerStrategy', | ||
) as unknown) as jest.MockedFunction< | ||
() => Promise<{ result: OAuthResult; privateInfo: any }> | ||
>; | ||
|
||
describe('createMicrosoftProvider', () => { | ||
it('should auth', async () => { | ||
const tokenIssuer = { | ||
issueToken: jest.fn(), | ||
listPublicKeys: jest.fn(), | ||
}; | ||
const catalogIdentityClient = { | ||
findUser: jest.fn(), | ||
}; | ||
|
||
const provider = new MicrosoftAuthProvider({ | ||
logger: getVoidLogger(), | ||
catalogIdentityClient: (catalogIdentityClient as unknown) as CatalogIdentityClient, | ||
tokenIssuer: (tokenIssuer as unknown) as TokenIssuer, | ||
authHandler: async ({ fullProfile }) => ({ | ||
profile: { | ||
email: fullProfile.emails![0]!.value, | ||
displayName: fullProfile.displayName, | ||
picture: 'http://microsoft.com/lols', | ||
}, | ||
}), | ||
clientId: 'mock', | ||
clientSecret: 'mock', | ||
callbackUrl: 'mock', | ||
}); | ||
|
||
mockFrameHandler.mockResolvedValueOnce({ | ||
result: { | ||
fullProfile: { | ||
emails: [ | ||
{ | ||
type: 'work', | ||
value: 'conrad@example.com', | ||
}, | ||
], | ||
displayName: 'Conrad', | ||
name: { | ||
familyName: 'Ribas', | ||
givenName: 'Francisco', | ||
}, | ||
id: 'conrad', | ||
provider: 'microsoft', | ||
photos: [ | ||
{ | ||
value: 'some-data', | ||
}, | ||
], | ||
}, | ||
params: { | ||
id_token: 'idToken', | ||
scope: 'scope', | ||
expires_in: 123, | ||
}, | ||
accessToken: 'accessToken', | ||
}, | ||
privateInfo: { | ||
refreshToken: 'wacka', | ||
}, | ||
}); | ||
const { response } = await provider.handler({} as any); | ||
expect(response).toEqual({ | ||
providerInfo: { | ||
accessToken: 'accessToken', | ||
expiresInSeconds: 123, | ||
idToken: 'idToken', | ||
scope: 'scope', | ||
}, | ||
profile: { | ||
email: 'conrad@example.com', | ||
displayName: 'Conrad', | ||
picture: 'http://microsoft.com/lols', | ||
}, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.