Connect with us

Hi, what are you looking for?

Design

Giving Temporary Access To Your ASP.NET Web API Using Hawk

aspdotnet

During the ASP.NET web development process, asp.net web developers can give temporary access to ASP.NET Web API using Hawk. What is Hawk? Hawk is an HTTP (Hyper Text Transfer Protocol) authentication protocol which is based on HMAC. Hawk helps ASP.NET developers to provide read-only access to a web API for some time. It is done by developers using a taken called ‘bewit’ which can be provided to a client by Web API. This token is valid only for HTTP GET calls. It can be used only for a specific period of time.

You can generate a bewit token using the following code:

var credential = new HawkCredential

{

Id = “dh37fgj492je”,

Key = “werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn”,

Algorithm = “hmacsha256”,

User = “john”

};

var bewit = Hawk.GetBewit(“localhost”,

new Uri(“http://localhost:8091/Api/HelloWorld”),

credential,

60000);

The GetBewit method assumes the following arguments

Host name

  • Complete request URI
  • Hawk credentials with info about the key and alogirthm to be used
  • A time-to-live setting for the token. It should be set for seconds.

This token serves as a string representation that can be added as an extra query string in Web API call.

new HttpRequestMessage(HttpMethod.Get,

“http://localhost:8091/Api/HelloWorld?bewit=” + bewit);

In this manner, you can share a link to your web API with a limited access for a short period of time. You will not have to share any security credentials. When it comes to service side it is very simple just as configuring the HawkMessageHandler as a component of the Web API configuration.

var handler = new HawkMessageHandler((id) =>

{

return new HawkCredential

{

Id = id,

Key = “werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn”,

Algorithm = “hmacsha256”,

User = “john”

};

});

config.MessageHandlers.Add(handler);

After this the handler can detect a bewit token in the query string by default. It will also perform all the necessary validations.

Written By

Blog produced by Eliz barrymore, Professional copywriter for Fusioninformatics.com provides information on iPhone Application Development, Android Application Development and more.

2 Comments

2 Comments

  1. Ramy

    July 14, 2013 at 12:00 pm

    Great article .. i found it so useful for me .. I aslo blog about Programming in my own little blog Search You Are Such A Computer Guy

  2. Ramy

    July 14, 2013 at 1:56 pm

    Great article . I found is so useful for me .. i also blog IT specially programming .. Search You Are Such A Computer Guy

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

You May Also Like

Careers/Jobs

Data from Grand View Research reveals that the global software development market was valued at over $429 billion in 2021, and it’s expected to grow...

Tech

Owing to the surge in popularity of machine learning, artificial intelligence, advanced analytics, and data science, the people that are much more interested in...

Tech

In web development, HTML, CSS, JavaScript, and other languages are used to create web pages. HTML is used to create static web pages, CSS...

Careers/Jobs

It is one of the most utilized and provided website development and desktop application development platforms used all over the companies and IT industries....