/
site.js
43 lines (39 loc) · 1.63 KB
/
site.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
// for details on configuring this project to bundle and minify static web assets.
// Write your JavaScript code.
$(function () {
function getToken() {
var iframe = $('#frmImplicit');
var idpUrl = $('#hdnImpersonationIDPUrl').val();
var idpRetUrl = $('#hdnImpersonationRetUrl').val();
var apiBaseUrl = $('#hdnApiBaseUrl').val();
var loggedInUser = $('#hdnloggedInUser').val();
$("#ddFriends").change(function () {
var user = $('option:selected', this).val();
var idpTokenUrl = idpUrl + '?username=' + user + '&' + idpRetUrl;
iframe.attr('src', idpTokenUrl);
});
iframe.on('load', () => {
var newHref = document.getElementById('frmImplicit').contentWindow.location.href;
let params = (new URL(newHref)).searchParams;
var token = params.get('token');
var apiUrl = apiBaseUrl + '/api/UserDetailsApi/GetPostsOfTargetUser?targetUser=' + loggedInUser;
$.ajax({
url: apiUrl,
crossDomain: true,
type: 'GET',
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', 'Bearer ' + token);
},
data: {},
success: function (resp) {
console.log('success: ', resp);
},
error: function (err) {
console.log('error: ', err);
}
});
});
}
getToken();
});