OAuth 2.0无法在本地IIS上运行

时间:2015-07-28 09:36:32

标签: c# iis oauth thinktecture-ident-server

我正在为我的应用程序(客户端凭据流)进行OAuth 2.0身份验证。我将Identity Server,ASP.NET Web Api作为一个应用程序,我将其作为客户端应用程序进行身份验证和控制应用程序。

当我的Web Api托管在IIS Express上时,一切正常。当我将其更改为本地IIS时,它不起作用。在IIS Express上,我将WindowsIdentity作为请求主体,但在本地IIS上我获得了Thinktecture,但没有声明。

我使用Owin个库进行OAuth,public class Startup { public void Configuration(IAppBuilder app) { app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions { Authority = ConfigurationManager.AppSettings["Authority"], RequiredScopes = new[] { "api" } }); } } 进行配置。这就是我的Startup类的样子:

var claims = ((ClaimsIdentity)p.Identity).Claims;
        var roleClaim = claims.Where(i => i.Type == "client_role").FirstOrDefault();
if (roleClaim == null)
{
   return null;
}

这是我检查主要身份的方式:

private static TokenResponse GetToken()
{
    var client = new OAuth2Client(new Uri(IdentityServerUri), clientId,clientScope);
    return client.RequestClientCredentialsAsync("scope").Result;
 }

当然,当我在本地IIS上时,我正在撤回null,因为此身份没有任何声明。

为什么我的应用在更改IIS时会改变行为?我试图在IIS配置中改变一些东西,但说实话,我是在盲目地做这件事。

有人知道这里有什么问题吗?

编辑: 我还会告诉我如何获取令牌和发送请求,这可能会导致问题。

var client = new HttpClient();
var tokenResponse = GetToken();
client.SetBearerToken(tokenResponse.AccessToken);
var result = client.GetStringAsync(requestUri).Result;

主要功能:

while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
    fputcsv($fp, array_values($row));
}

0 个答案:

没有答案
相关问题