This sample shows how to prompt a user to authorize a cloud service that can call APIs on Visual Studio Team Services on behalf of the user.
To learn more about OAuth in Visual Studio Team Services, see Authorize access with OAuth 2.0
These instructions assume you will be deploying this sample app to an Azure web site. To learn more and to get started, visit Get started with Azure Web Sites and ASP.NET.
- Register an OAuth client app in Visual Studio Team Services (https://app.vssps.visualstudio.com/app/register)
- The callback URL should be https://yoursite.azurewebsites.net/oauth/callback, where "yoursite" is the name of your Azure web site
- Clone this repository
- Open the solution (VstsOAuthSample.sln) in Visual Studio 2015 or later
- Update the following settings in web.config to match the values in the app you just registered:
- App ID
- App Secret (use the "Client Secret" shown on the VSTS Application Settings page, not the App Secret)
- Scope (space separated)
- Callback URL
- Build the solution (this will trigger a NuGet package restore, which will pull in all dependencies of the project)
- Deploy the app to Azure
- Navigate to the deployed app (https://yoursite.azurewebsites.net)
- Confirm your App ID, scope, and callback URL are displayed properly
- Click Start
- # to Visual Studio Team Services (if prompted)
- Review and accept the authorization request
If everything is setup properly, Visual Studio Team Services will issue an access token and refresh token and both values will be displayed. You should keep these values secret. Also a new authorization will appear in your profile page.
With the access token you can invoke Visual Studio Team Services REST APIs by providing the access token in the Authorization header.
Authorization: Bearer {access token}