OAuth2 Web API 2身份验证



我正在学习如何保护我正在构建的测试API的安全性,我希望实现安全性,即用户注册,然后他请求API密钥,他将在应用程序中使用该密钥向我的API进行身份验证。

我开始实现这一点:https://github.com/vchatterji/OAuth2ClientCredentialGrant我得到了第一部分,用户可以注册,然后请求并接收ConsumerKey&ConsumerSecret,保存在Azure表中。

我的问题是,我不确定我使用的是什么Flow。文档没有说明要更改StartupAuth:中的任何内容

  app.UseCookieAuthentication(new CookieAuthenticationOptions());
          app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
        // Configure the application for OAuth based flow
        PublicClientId = "self";
        OAuthOptions = new OAuthAuthorizationServerOptions
        {
            TokenEndpointPath = new PathString("/Token"),
            Provider = new ApplicationOAuthProvider(PublicClientId),
            AuthorizeEndpointPath = new    PathString("/api/Account/ExternalLogin"),
            AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
            AllowInsecureHttp = true
        };

我正在尝试使用Fiddler进行身份验证,并尝试了许多不同的请求,但我最常见的错误是不支持的授予类型。

根据我在这里的情况,我应该使用什么类型的补助金?上面说在/Token进行身份验证,但其他文档说api/Token,哪个是正确的?

如有任何关于编写身份验证请求的帮助,我们将不胜感激。

我遇到了同样的问题,因为没有在请求的正文中发送数据。。。像这样:

POST http://localhost:60543/oauth/token HTTP/1.1
Host: localhost:60543
Connection: keep-alive
Content-Length: 54
Cache-Control: no-cache
Origin: chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36
Postman-Token: 85363928-a3d6-f9ad-c368-ab6019027a02
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: en,fr;q=0.8,pt-PT;q=0.6,pt;q=0.4,en-US;q=0.2,es;q=0.2
username=peter&password=123456&grant_type=password

请确保在请求的标头中设置内容类型。

最新更新