Reputation: 349
I am trying to authenticate REST call with OAuth, but I couldn't find any sample regarding this. Please be kind enough to guide me on this ( provide sample).
I am referring below documentation from Microsoft.
https://www.visualstudio.com/en-us/docs/integrate/get-started/rest/basics
I can authenticate this using NTLM (below is the sample I use) . There is node library available for same (https://www.npmjs.com/package/httpntlm). But I need something similar for OAuth.
httpntlm.patch(options, function(err,res) {
console.log("patch complete");
console.log(res.body);
})
Upvotes: 3
Views: 4470
Reputation: 225
I am not sure of the technologies you are using to achieve this but if your application is .Net/ .Net Core MVC application then Microsoft has provided sample code for the same: VSTS Sample Code C#
However, if your application is like mine, SPA (on angular) and .Net Core back end then there is no document clearly describing which parts should go where and how to achieve OAuth flow in such case. To answer that, i have achieved this in following way:
Thats it, OAuth flow can be achieved in Angular and .Net Core in above way.
Please note, this is something not documented by microsoft so there might be flaws in this approach which i am open to learn and rectify.
Please comment to get sample repo.
Upvotes: 0
Reputation: 51183
You could be able to Authorize access to REST APIs with OAuth 2.0 in VSTS. It's only available with VSTS for now, TFS2017 is not support. You could also check this question: TFS 2015 REST API Authentication. And there has been a related uservoice.
First, you'll register your web app and get an app ID from Visual Studio Team Services. Using that app ID, you'll send your users to Visual Studio Team Services to authorize your app to access their accounts there. Once they've done that, you'll use that authorization to get an access token for that user. When you call Visual Studio Team Services APIs on behalf of that user, you'll use that user's access token.
A C# sample that implements OAuth to call Visual Studio Team Services REST APIs in GitHub for your reference: vsts-dotnet-oauth-sample
Upvotes: 4