Token based Authentication for WCF HTTP/REST Services: The Client

If you wondered how a client would have to look like to work with the authentication framework, it is pretty straightfoward:

  1. Request a token
  2. Put that token on the authorization header (along with a registered scheme) and make the service call

e.g.:

var oauth2 = new OAuth2Client(_oauth2Address);
var swt = oauth2.RequestAccessToken(
"username", "password", _baseAddress.AbsoluteUri);
 
var client = new HttpClient { BaseAddress = _baseAddress };
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer"
, swt);
var response = client.Get("identity");
response.EnsureSuccessStatusCode();

HTH

This entry was posted in IdentityModel, IdentityServer. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s