【问题标题】:OAuth2 Web API 2 authenticationOAuth2 Web API 2 身份验证
【发布时间】:2015-03-02 01:15:06
【问题描述】:

我正在学习如何保护我正在构建的测试 API,并且我想在用户注册然后他请求一个 API 密钥来实现安全性,他将在他的应用中使用该密钥来对我的 API 进行身份验证。

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

我的问题是我不确定我使用的是什么流程文档没有说明要更改 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,哪个是正确的?

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

【问题讨论】:

    标签: oauth-2.0 asp.net-web-api2


    【解决方案1】:

    由于没有在请求正文中发送数据,我遇到了同样的问题......就像这样:

    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

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

    【讨论】:

      猜你喜欢
      • 2014-01-28
      • 2017-07-27
      • 2017-03-04
      • 2016-04-05
      • 2015-06-06
      • 2013-03-06
      • 2018-07-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多