connecting to TFS using windows auth in electron app - javascript

i'm building an electron app that connect to a TFS server and retrieve some data from it.
They use Windows credential to access TFS , how can i connect to TFS using Windows credential through chrome or node.js ?
i tried this code but give me 401 : unauthorized
$.ajax({
url: 'https://tfs.myserver.com:8090/tfs/IKM.TPC.Projects/MR/_workitems',
type: 'GET',
dataType: 'json',
xhrFields: {
withCredentials: true
}
})
.done(function (data) {
$('#result').text(data);
})
.fail(function (jqXHR, textStatus, errorThrown) {
$('#result').text(textStatus);
});

Simple steps:
Create a login page to let user login with username and password
Store username and password in a variable, cookie or local storage
Send the request by using httpntml with username, password, domain

Related

Is it possible to use GET & POST inside one $.ajax for login?

Good day,
We are building a project that uses WordPress for the marketing(normal pages, blogs, etc) and angular for the more functional side of this project. My current issue is we use the wordpress side for registration, subscribing to newsletter, and logging in. Newsletter and registration is now okay but I have a problem with the login. I'm using a custom bootstrap form, and use ajax. I'm given an api to get the login token first, then include that token in post for logging in.
This is currently what I got in my scripts.js:
$('#login-button').click(function(event) {
event.preventDefault();
// extracting the token
$.get("https://sample-dummy-url/Account/Loginwp", function(data, status){
// setting the token to loginToken variable to include in logging in
loginToken = $(data).find("input[name='__RequestVerificationToken']").val();
// checking if token is extracted
console.log(loginToken);
});
// I know this will be empty outside of the function of getting the token, but this is my current idea
console.log(loginToken);
// setting the variable to pass for logging in
let login = {
Username: $('#loginUsername').val(),
Password: $('#loginPassword').val(),
button: 'login',
// this is where I supposedly assign the extracted token but I know this is empty
__RequestVerificationToken: loginToken,
RememberLogin: $('#loginRememberMe').is(":checked"),
}
// ajax for logging in
$.ajax({
url: 'https://sample-dummy-url/Account/Login',
headers: {
'Access-Control-Allow-Origin': '*',
'Accept': 'application/json',
'Content-Type': 'application/json; charset=UTF-8'
},
type: 'POST',
dataType: 'json',
data: JSON.stringify(login),
success: function(msg, textStatus, jqXHR) {
console.log("logged in");
},
error: function(msg, textStatus, jqXHR) {
console.log(msg);
console.log(textStatus);
console.log(jqXHR);
},
});
});
My idea was only to invoke the getting of token when login button is clicked, then extract the token to a variable so I could include it in the login object so that when I use another ajax to post for login. I know this might be not the best/ideal/practical implementation, but I am truly open for suggestions & enlightenment of the proper way of doing it.
Thank you for any help.

AWS Cognito Authorize API call Using Javascript

I have a API which Authenticate by AWS cognito service. i wanted to call it using ajax .i used below code for that.
$.ajax({
url: 'https://XXXXXXXXX.execute-api.us-east-2.amazonaws.com/XXXXXXXX/setusername',
type: 'POST',
dataType: 'json',
data: {},
header :{'Authorization':result.getIdToken().getJwtToken()},
success: function (data, textStatus, xhr) {
console.log(data);
},
error: function (xhr, textStatus, errorThrown) {
console.log('Error in Operation');
}
});
but it gives me below error when i execute it.(Note: when i remove cognito Auth from API gateway this working fine)
Console Error
and below is my integration response
try this library to sign the call to your API Lambda method https://github.com/mhart/aws4
or are you using a custom auth?

connection to TFS-Api from Javascript Client

I am trying to connect a JavaScript client with a TFS 2015 API to get some information and save it in my SQL Database, but I am having challenges establishing this connection with JavaScript. They are using Windows authorization.
I used this code but it didn't work:
$.ajax({
url: 'https://tfs........',
type: 'GET',
dataType: 'json',
xhrFields: {
withCredentials: true
}
})
.done(function (data) {
console.log(data);
})
.fail(function (jqXHR, textStatus, errorThrown) {
console.log(textStatus);
});
Can anyone help me please?
Refer to these 2 threads(one, two), check if the Access-Control-Allow-Origin is a wildcard like '*'. This is not allowed.
Update:
Refer to this case who have similar issue with you: connecting to TFS using windows auth in electron app.
You could create a login in page, and store username and password in cookies. Then use httpntlm to do this request.

Twitter API setting Authorization header in jQuery AJAX

I have a problem. I have the Authorization header generated by OAuth Tool in Twitter (I hid value of keys)
Authorization: OAuth oauth_consumer_key="xxxxxxxxxxxxxxxx", oauth_nonce="xxxxxxxxxxxxxxxx", oauth_signature="xxxxxxxxxxxxxxx", oauth_signature_method="HMAC-SHA1", oauth_timestamp="xxxxxxxxx", oauth_version="1.0"
And I have a AJAX code:
$.ajax({
url: 'https://api.twitter.com/1.1/search/tweets.json?q=%23freebandnames&since_id=24012619984051000&max_id=250126199840518145&result_type=mixed&count=4',
type: 'GET',
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', 'OAuth oauth_consumer_key="xxxxxxxxxxxxxxx", oauth_nonce="xxxxxxxxxxxxxxx", oauth_signature="xxxxxxxxxxxxxxx", oauth_signature_method="HMAC-SHA1", oauth_timestamp="xxxxxxxxx", oauth_version="1.0"');
},
dataType: "jsonp",
success: function(data) {
console.log("Success: " + data);
}
},
error: function(data) {
console.log("Error " + data);
}
});
But this code returned error
Object {readyState: 4, status: 404, statusText: "error"}
Here is part of documentation Twitter REST API which I use:
https://dev.twitter.com/rest/reference/get/search/tweets
What is wrong? Any ideas?
Twitter does not support generating the authentication header from a webpage. You must go through the "handshake" using their site to authenticate and redirecting back to your webpage.
If you want to avoid this and keep your oauth keys locally, you will need to build a server which can authenticate using stored keys. Then your webpage will make Twitter requests via your server.

Facebook access_token error in Blackberry

In my Blackberry app using phonegap, I have Facebook share feature and I am doing this using phonegap's childbrowser. After I login to Facebook, access_token is to be requeted. For this I am using the following code :
$.ajax({
url:'https://graph.facebook.com/oauth/access_token?client_id='+my_client_id+'&client_secret='+my_secret+'&redirect_uri=http://www.facebook.com/connect/login_success.html',
data: {},
dataType: 'text',
type: 'POST',
success: function(data, status){
alert(22);
// We store our token in a localStorage Item called facebook_token
localStorage.setItem(facebook_token, data.split("=")[1]);
window.plugins.childBrowser.close();
app.init();
},
error: function(error) {
alert("fail"+error['message']);
window.plugins.childBrowser.close();
}
});
But the control is not going inside the success section instead it is going inside error section. What may be the problem. When I try to find the error using "alert("fail"+error['message']);", it is coming as undefined. Please help me to resolve this.

Categories