-
Notifications
You must be signed in to change notification settings - Fork 0
Fix: Azure endpoint return all users from ioet #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
cxcarvaj
merged 6 commits into
master
from
TT-537-azure-endpoint-doesnt-return-the-complete-users
Feb 16, 2022
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
67c6f70
Fix: Azure endpoint return all users from ioet
cxcarvaj 504a0f3
Fix: Azure endpoint return all users from ioet
cxcarvaj 55a06c2
refactor: Refactor of code smells
cxcarvaj bbf68f2
style: Changes requested by review
cxcarvaj 2a1dc12
style: Changes requested by reviews
cxcarvaj 462117f
style: Changes requested by Sandros review
cxcarvaj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
71 changes: 45 additions & 26 deletions
71
nodejs-functions/src/handlers/automatic-clock-outs/msal_client.js
This file contains hidden or 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 |
---|---|---|
@@ -1,27 +1,46 @@ | ||
const axios = require("axios") | ||
const msal = require('@azure/msal-node'); | ||
const config = require("./config"); | ||
|
||
const findUsersInMS = async() => { | ||
const {clientId, authority, clientSecret} = config; | ||
const endpoint = 'https://graph.windows.net/ioetec.onmicrosoft.com' | ||
const configuration = { | ||
auth: { | ||
clientId: clientId, | ||
authority: authority, | ||
clientSecret: clientSecret | ||
} | ||
}; | ||
|
||
const cca = new msal.ConfidentialClientApplication(configuration); | ||
const clientCredentialRequest = { | ||
scopes: ['https://graph.windows.net/.default'], | ||
}; | ||
const response = await cca.acquireTokenByClientCredential(clientCredentialRequest) | ||
const token = response.accessToken | ||
return axios.get(`${endpoint}/users?api-version=1.6&$select=displayName,otherMails,objectId`, | ||
{ 'headers': { 'Authorization': token } }) | ||
} | ||
|
||
module.exports = { findUsersInMS }; | ||
const axios = require('axios'); | ||
const config = require('./config'); | ||
|
||
const getToken = async () => { | ||
const { clientId, userNameMS, userPasswordMS } = config; | ||
const endpoint = | ||
'https://ioetec.b2clogin.com/ioetec.onmicrosoft.com/B2C_1_accesstoken/oauth2/v2.0/token'; | ||
cxcarvaj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const params = new URLSearchParams(); | ||
|
||
params.append('username', userNameMS); | ||
params.append('password', userPasswordMS); | ||
params.append('grant_type', 'password'); | ||
params.append('scope', clientId); | ||
params.append('client_id', clientId); | ||
params.append('response_type', 'token'); | ||
|
||
const headers = { | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
}, | ||
}; | ||
|
||
return axios.post(endpoint, params, headers) | ||
.then((result) => { | ||
return result.data.access_token; | ||
}) | ||
.catch((err) => { | ||
console.log(`Invalid request to: ${endpoint}`); | ||
}); | ||
}; | ||
|
||
const findUsersInMS = async () => { | ||
const endpoint = 'https://timetracker-api.azurewebsites.net/'; | ||
const token = await getToken(); | ||
|
||
const headers = { | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
}; | ||
|
||
return axios.get(`${endpoint}/users`, headers); | ||
}; | ||
|
||
module.exports = { findUsersInMS }; |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.