You can look at DotNetOpenAuth . It has a client library that you can easily install from NuGet here . Using DotNetOpenAuth
, all OAuth plumbing is handled backstage.
DotNetOpenAuth:
When you install the NuGet package: https://www.nuget.org/packages/DotNetOpenAuth.Ultimate/4.3.3.13295
You can configure the OAuth client as follows:
var authorizationServerDescription = new AuthorizationServerDescription { ProtocolVersion = ProtocolVersion.V20, TokenEndpoint = new Uri("https://yourUrl/token"), AuthorizationEndpoint = new Uri("https://yourUrl/authorize") }; var client = new WebServerClient(authorizationServerDescription, "ClientIdentifier", "ClientSecret");
You can then query IAuthorizationState
as follows:
// Resource Owner Password Flow client.ExchangeUserCredentialForToken("userName", "password"); // Client Credential Flow client.GetClientAccessToken();
IAuthorizationState contains an AccessToken
that you can use to authorize against your Api. If a RefreshToken is provided, you can also update your authorization using:
client.RefreshAuthorization(AuthorizationState);
ThinkTecture:
Alternatively you can use Thinktecture.IdentityModel
. If you decide to use the Thinktectures IdentityModel, be sure to check out this message: Introducing OAuth2 codestream support and token updates in ThinkTecture IdentityServer . This not only explains how to configure OAuth Token Server using Thinktecture, but also how to use the client, including sample code. Of course, you can use this client to check on another OAuth 2.0 server if the parameters are implemented in accordance with the OAuth specifications.
OAuth 2.0 Playground If you want a better look at the OAuth 2.0 stream, be sure to check out the Google OAuth 2.0 Playground . I think that many people do not know that you can test your own server with it. Just click the "Settings" icon in the upper right corner and set:
OAuth Endpoints: Custom
And you are good to go.
source share