1. Scene
According to the OAuth 2.0 specification, the scenario takes place in the (D) (E) node of the following flowchart, obtaining access token based on the authorization code that has been obtained.
2. Realize the Environment
Dotnetopthauth v5.0.0-alpha3, ASP.net MVC 5,. NET Framework 4.5.1.
2. Main implementation Sample code
2.1. Authorization Server Implementation Code
2.1.1. asp.net MVC Controller Implementation code
Using System.Threading.Tasks;
Using SYSTEM.WEB.MVC;
Using CNBlogs.Open.Domain.Entities.OpenAuth;
Using Dotnetopenauth.oauth2;
Using Dotnetopenauth.messaging;
Namespace CNBlogs.Open.Web.Controllers
{public
class Oauthcontroller:controller
{public
async Task<actionresult> Token ()
{
var authserver = new Authorizationserver (new Authorizationserverhost ()) ;
var response = await authserver.handletokenrequestasync (Request);
return response. Asactionresult ();}}