Created
March 5, 2018 17:21
-
-
Save baltuonis/80a736b7714baa0b66b44e9708950e8d to your computer and use it in GitHub Desktop.
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
//// CALL AN API | |
callAPI() { | |
// FIXME: get cached token? | |
AuthService.app.acquireTokenSilent(['https://apim-teamsoftware-cus-authtest-dev.azure-api.net/authtest']).then(token => | |
const url = 'https://apim-teamsoftware-cus-authtest-dev.azure-api.net/authtest/api/HttpTriggerCSharp2' | |
return this.fetch(token, url).then(res => console.log(res)) | |
) | |
fetch = (token, url) => { | |
const headers = new Headers({ | |
Authorization: `Bearer ${token}`, | |
'Ocp-Apim-Subscription-Key': 'c322f22da3724b73aa7596e6e37e704a' | |
}); | |
const options = { headers }; | |
return fetch(url, options) | |
.then(response => response.json()) | |
.catch(response => { | |
throw new Error(response.text()); | |
}); | |
} | |
////////////////// LOGIN CODE | |
this.applicationConfig = { | |
clientID: '2dd11a93-57e0-43a4-91a1-4fb8169a27d3', | |
scopes: [ | |
'user.read', | |
'openid', | |
// 'https://apim-teamsoftware-cus-authtest-dev.azure-api.net/user_impersonation', | |
'offline_access', | |
] | |
} | |
return this.app.loginPopup(this.applicationConfig.scopes).then(.......) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment