Skip to content

ronneylira/DotNetOpenAuth.MicrosoftOAuth2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

DotNetOpenAuth OAuth2 Client for Microsoft

This is an OAuth2 client to use with the DotNetOpenAuth project. The following code is an adaptation of Matt Johnson's DotNetOpenAuth.GoogleOAuth2 project

Setup

  1. Setup your Microsoft App using the Application Registration Portal.

  2. Compile from source and reference. (NuGet coming soon)

  3. Register the client instead of the existing Microsoft OpenId client.

    var client = new MicrosoftOAuth2Client("yourClientId", "yourClientSecret", new[] { "list", "of", "scopes", "you", "need" });
    OAuthWebSecurity.RegisterClient(client);
    
  4. Just an observation since i suffered with it, microsoft calls clientID as Application ID and clientSecret as Password

Usage

Just like any other OAuthWebSecurity client, except you need one extra hook:

    // add this line
    returnUrl += MicrosoftOAuth2Client.RewriteRequest();

    // it belongs right before your existing call to
    OAuthWebSecurity.VerifyAuthentication(....)

This is needed because Microsoft requires that any extra querystring parameters for the redirect be packed into a single parameter called state. Since OAuthWebSecurity needs two parameters, __provider__ and __sid__ - we have to rewrite the url.

Note: The RewriteRequest method will unpack the state parameter and place its contents back into the regular querystring. So if you are looking for a state value such as ReturnUrl, you will find it has been moved to Request.QueryString["ReturnUrl"].

Disclaimer

This is released under the MIT licence. Do what you want with it.

About

DotNetOpenAuth OAuth2 Client for Microsoft

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages