标签: thinktecture-ident-model

是否可以从消息处理程序访问Controller/Action属性?

是否有实用的方法来访问从Message Handler/DelegatingHandler装饰控制器或操作的属性?

佩德罗Felix的博客文章,它看起来像消息处理程序的正在酝酿太早,直到控制器调度信息处理器运行的信息将不可用.正确?

关于我的用例:
我正在使用Thinktecture身份模型,能够在中找到AllowAnonymous属性是有用的AuthenticationHandler.

asp.net-web-api thinktecture-ident-model

6
推荐指数
1
解决办法
1249
查看次数

使用Thinktecture的AngularJs ASP.NET WebApi身份验证

我正在尝试创建一个AngularJs Web,它将登录名和密码发送到ASP.NET WebApi后端,并使用Thinktecture登录该用户.

我使用WS-Federation让Thinktecture与其他项目ASP.NET MVC一起正常工作.现在我正在尝试做类似的事情,但改变一些组件,我不能让它工作.

如何从ASP.NET WebApi将用户名和密码发送到Thinktecture并验证它?

using System.Collections.Generic;
using System.IdentityModel.Services;
using System.Web.Http;
using WebApi_AngularJs.Model;

namespace WebApi_AngularJs.Controllers
{
    public class AuthorizationController : ApiController
    {    
        // POST: api/Authorization
        public LoginResponse Post([FromBody]Login data)
        {
            //HOW TO SEND data.user and data.password to ThinkTecture and get
            //response if user valid or not??
            var response = new LoginResponse { access_token = "token", data = "data"};
            return response;
        }   

    }
}
Run Code Online (Sandbox Code Playgroud)

谢谢!

authentication asp.net-web-api angularjs thinktecture-ident-model thinktecture-ident-server

6
推荐指数
2
解决办法
7900
查看次数

如何在PCL中解码与Xamarin Android兼容的JWT

我有一个带有PCL程序集,Android应用程序和iOS应用程序的Xamarin.Forms解决方案,我想解码PCL中的JWT.

我不能使用Thinktecture.IdentityModel.Core 1.1.0System.IdentityModel.Tokens.Jwt 4.0.0JWT 1.3.2,因为它们都不能添加到以' portable-net45 + win + MonoAndroid10 +为目标的项目中MonoTouch10 '.

我能够从NuGet 添加Jose JWT 1.7.0并验证它在单元测试中有效,但它导致我在我的Xamarin Android项目中得到以下构建错误...

加载程序集时出现异常:System.IO.FileNotFoundException:无法加载程序集'System.Web.Extensions,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'.也许它在Mono for Android配置文件中不存在?

建议?

.net xamarin.ios xamarin.android jwt thinktecture-ident-model

6
推荐指数
1
解决办法
1110
查看次数

如何在Identity Server 3中使用Windows身份验证?

我的目标是使用Web服务的Angular应用程序,使用Windows身份验证对应用程序/ Web服务的用户进行身份验证.用户应该能够登录我们的Windows域中的计算机,打开浏览器并使用Angular应用程序而无需再次登录.

研究

我从https://github.com/IdentityServer/IdentityServer3.Samples/下载了所有源代码示例

我使用了最简单的OAuth2演练示例.没问题.

然后我打开了Web Host(Windows Auth All-In-One)示例.在评论出导致问题的两行代码后,我可以恢复和构建项目(Clients.cs行313,359,设置'AllowAccessTokensViaBrowser = false'.可能不相关.)

当应用程序运行时,我可以在localhost:44333上看到IdentityServer3登录页面.大.

我还可以在localhost:44333/windows上看到Windows身份验证服务元数据(SAML文档).还有,很棒.

问题是,我不知道接下来该做什么.本文档似乎建议下一步涉及编写一个调用Windows身份验证服务来获取令牌的客户端:

http://github.com/IdentityServer/IdentityServer3/issues/1463

这是正确的方法吗?我无法使代码示例工作.我甚至不确定我是否可以指向OAuth2Client正确的地方.请有人解释这个过程,或者给我一个工作客户的例子吗?提前谢谢你的帮助:)

编辑

我一直在做进一步的研究.我检查了Identity服务器的日志,以确保在配置期间完成添加WS-Federation端点操作.确实如此.

然后我创建了一个简单的控制台应用程序来调用Windows身份验证服务,如下所示:github.com/IdentityServer/IdentityServer3/issues/2318

导入Thinktecture.IdentityModel.Client后,我修改了该页面上的代码以适应我的端口号等,我最终得到了这个:

   var handler = new HttpClientHandler
   {
       UseDefaultCredentials = true
   };
   var oauthClient = new OAuth2Client(
                    new Uri("https://localhost:44333/windows/token"),
                    handler);

   var result = oauthClient.RequestCustomGrantAsync("windows").Result;
Run Code Online (Sandbox Code Playgroud)

我的结果对象仍然有一个NotFound的HttpErrorStatusCode ,这让我很伤心.

另一个编辑

我尝试将客户端指向Identity Server端点,如Branimir所示.所以我的代码现在写道:

var oauthClient = new OAuth2Client(
   new Uri("https://localhost:44333/connect/token"),
   handler);
Run Code Online (Sandbox Code Playgroud)

这也不起作用.这是Identity Server日志所说的内容:

Start token request …
Run Code Online (Sandbox Code Playgroud)

authentication thinktecture-ident-model thinktecture-ident-server identityserver3

6
推荐指数
1
解决办法
3498
查看次数

AuthorizationCodeProvider: Create 从未被调用,如何生成授权码?

我正在设置我自己的 OAuth2 服务器。到目前为止,我已经成功地实现GrantResourceOwnerCredentials了我的OAuthAuthorizationServerProvider. 现在,因为我正在为我们的业务开发应用程序,所以我想实施 OAuth2 授权代码授权。

我试图按照这里的指示https://docs.microsoft.com/en-us/aspnet/aspnet/overview/owin-and-katana/owin-oauth-20-authorization-server但在我的实施中,我没有找到了如何达到(我在 中设置的)的Create调用。AuthorizationCodeProviderOAuthAuthorizationServerOptions

我已经简要检查了TokenEndpointPath使用(错误的)代码参数访问 是否有效,并且在调试器中我看到我AuthorizationCodeProviderReceive调用被击中。当然没有成功,因为我发送的代码是“sometestcode”而不是真正的代码,但是代码被命中了,这意味着我走在正确的道路上。

这是我到目前为止所拥有的:

    public override Task ValidateClientRedirectUri(OAuthValidateClientRedirectUriContext context)
    {
        if (OAuthRepository.GetClient(context.ClientId) != null)
        {
            var expectedRootUri = new Uri(context.Request.Uri, "/");

            if (context.RedirectUri.StartsWith(expectedRootUri.AbsoluteUri))
            {
                context.Validated();
                return Task.FromResult<object>(null);
            }
        }

        context.Rejected();
        return Task.FromResult<object>(null);
    }

    public override Task AuthorizeEndpoint(OAuthAuthorizeEndpointContext context)
    {
        // I know this is wrong but it's just a start and not the focus of this SO …
Run Code Online (Sandbox Code Playgroud)

oauth-2.0 thinktecture-ident-model asp.net-web-api2

6
推荐指数
1
解决办法
2415
查看次数

Thinktecture.IdentityModel with SimpleMembership

我想使用ASP.NET SimpleMembership来验证使用我的WebAPI的用户.Thinktecture有一个名为Thinktecture.IdentityModel(http://thinktecture.github.com/Thinktecture.IdentityModel.45/)的精彩认证库,其中包含一个将Forms Auth与Basic Auth()联系起来的示例.但是,该示例使用Membership.ValidateUser(),它在没有ASP.NET成员资格提供程序的情况下不起作用,SimpleMembership(源代码)不支持(编辑:这不完全正确,请参阅下面的Mark答案).


编辑:

这是我做的:

1)创建一个新的MVC Internet应用程序

2)通过NuGet安装Thinktecture.IdentityModel

3)通过脚手架创建模型和api控制器:

public class Goober
{
    public int GooberId { get; set; }
    public string GooberWords { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

4)运行项目,创建一个新用户并使用Fiddler创建一个新的Goober

5)为GetGoober添加[授权](int id)

6)在WebApiConfig.cs中添加:

var authConfig = new AuthenticationConfiguration();

authConfig.AddBasicAuthentication((userName, password) =>
    Membership.ValidateUser(userName, password));

config.MessageHandlers.Add(new AuthenticationHandler(authConfig));
Run Code Online (Sandbox Code Playgroud)

当我运行该项目并用Fiddler命中api/goober/1时,我得到了一个401 www-Authenticate:未指定.但是如果我首先使用AccountController登录然后使用Fiddler我得到200并且一切都很好.

编辑

好的,我认为问题与我最初的问题无关.我怀疑它与模板中SimpleMembership的初始化有关.当我打开项目并运行调试然后用Fiddler点击api我无法通过Auth.但是,当我只是点击网络前端的"注册"链接时,我就会通过Auth.我猜是因为在AccountController中调用了InitializeSimpleMembershipAttribute,所以在调用控制器之前不会初始化?


我尝试在Membership.ValidateUser()的位置使用WebSecurity.Login(),但这不起作用.

我对如何实现这一点感到茫然.有人有建议吗?或者我可能试图从错误的角度解决这个问题?

asp.net authentication asp.net-mvc asp.net-web-api thinktecture-ident-model

5
推荐指数
1
解决办法
2892
查看次数

如何使存储在Web API SessionToken中的ClaimsIdentity声明过期/更新

我使用优秀的Thinktecture.IdentityModel库在ASP.NET Web API项目中执行身份验证/授权,该项目将从移动设备和Web客户端使用.我正在使用基本身份验证来验证移动客户端以访问web api,并利用Thinktecture.IdentityModel提供的内置SessionToken生成.但是我对如何撤销添加到ClaimsIdentity声明集合中的声明有一些担忧,然后(我认为)编码到提供给客户端的SessionToken中......

这是我到目前为止:

按照IdentityModel示例项目中的示例,我创建了以下类

public static class  SecurityConfig
{
  public static void ConfigureGlobal(HttpConfiguration globalConfig)
  {
      globalConfig.MessageHandlers.Add(new AuthenticationHandler(CreateConfiguration()));
  }

  public static AuthenticationConfiguration CreateConfiguration()
  {
      var authentication = new AuthenticationConfiguration()
          {
              ClaimsAuthenticationManager = new MyClaimsTransformer(),
              RequireSsl = false, //TODO:TESTING only
              EnableSessionToken = true,
              SessionToken = new SessionTokenConfiguration()
              {
                  EndpointAddress = "/Authenticate"
              }
          };
       authentication.AddBasicAuthentication(Membership.ValidateUser);

      return authentication;
   }
}
Run Code Online (Sandbox Code Playgroud)

这是从我的Global.asax类调用的

SecurityConfig.ConfigureGlobal(GlobalConfiguration.Configuration);
Run Code Online (Sandbox Code Playgroud)

移动设备从个人收集用户名和密码,并正确设置身份验证标头并将凭据提供给必要的Web端点 http://myhost/api/Authenticate

在服务器上,使用用户名/密码调用Membership.ValidatUser,如果验证,MyClaimsTransformer则调用Authenticate方法.

public class ClaimsTransformer : ClaimsAuthenticationManager
{
   public override ClaimsPrincipal Authenticate(string resourceName, ClaimsPrincipal incomingPrincipal)
   {
     if …
Run Code Online (Sandbox Code Playgroud)

c# claims-based-identity asp.net-web-api thinktecture-ident-model

5
推荐指数
1
解决办法
5267
查看次数

ASP.NET Identity和Thinktecture.IdentityModel库如何相互关联?

我刚刚开始在我们的web api服务中实现安全性(主要是作为一项研究工作).
并且遇到了新的ASP.NET身份和相当成熟的Thinktecture.IdentityModel库.

由于我对这一堆认证/授权机制没有经验,所以非常混乱.现在我不能说这些库是相同的还是彼此正交的.

我将不胜感激任何澄清应该使用哪一个以及何时使用.

.net security asp.net-web-api thinktecture-ident-model

5
推荐指数
1
解决办法
2339
查看次数

从Web API 2基于声明的身份验证迁移到ThinkTecture

我发现微软基于声明的身份验证的实现并没有真正达到真正的基于声明的设置的期望,我觉得ThinkTecture在替换Web API实现方面做得很好.

我想知道是否有人有一个指南或博客文章供人们从用于AccountController的VS2013的默认SPA模板转移到ThinkTecture方法.

我也喜欢默认的Microsoft Web API AccountController,它将为AspNetUsers和Roles创建表,但我不确定ThinkTecture是否做同样的事情.

我想我在ThinkTecture拥有的所有存储库之间有点困惑.是否有任何人有什么用,术语坚实的指导IdentityServer,IdentityModel.45AuthorizationServer

我只想放弃整个Microsoft方法并开放使用适当的真正的基于声明的方法,但我EF6 migrations在Identity表方面需要帮助,需要使用哪些项目,或者如何放弃整个AccountController方法在SPA-Template for VS2013.我看过Dominick的博客,它看起来真的很棒,但我还没有找到一篇有助于从Web API方法转向ThinkTecture思维方式的帖子.

claims-based-identity asp.net-web-api thinktecture-ident-model thinktecture-ident-server

5
推荐指数
1
解决办法
2007
查看次数

System.Web.Mvc 5.2.2.0与aspnet_compiler的5.2.3.0版本控制问题

在Visual Studio中打开视图编译时遇到问题.我有一个相当标准的ASP.NET MVC 5应用程序,有很多参考.我引用System.Web.Mvc 5.2.3.0(最新版本),但编译似乎与v.5.2.2.0 vs 5.2.3.0有问题.优秀的工具AsmSpy(https://github.com/mikehadlow/AsmSpy)告诉我哪些程序集引用了System.Web.Mvc的哪个版本:

Reference: System.Web.Mvc
   5.1.0.0 by Autofac.Integration.Mvc
   5.0.0.0 by Glimpse.Mvc5
   5.0.0.0 by Microsoft.Web.Mvc
   3.0.0.0 by Mindscape.Raygun4Net.Mvc
   5.2.3.0 by Myrepo.Web.Common
   5.2.3.0 by MyApp
   5.2.2.0 by Thinktecture.IdentityModel.Owin.ResourceAuthorization.Mvc
Run Code Online (Sandbox Code Playgroud)

所以,有罪的是Thinktecture.IdentityModel.Owin.ResourceAuthorization.Mvc.但是,我已经将程序集绑定重定向添加到应用程序的根web.config,如下所示:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <!-- lots more -->
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
      <!-- lots more -->
    </assemblyBinding>
  </runtime>
Run Code Online (Sandbox Code Playgroud)

为了试图找到问题的根源,我打开了Diagnostic构建日志,它在260,000行日志中向外吐出,包括:

16>  Unified primary reference "System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35". (TaskId:183)
16>      Using this version instead of original version "5.1.0.0" in "C:\Users\ErikBrandstadmoen\Source\Repos\myrepo\packages\Autofac.Mvc5.3.3.4\lib\net45\Autofac.Integration.Mvc.dll" because of a …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc aspnet-compiler thinktecture-ident-model

5
推荐指数
1
解决办法
5088
查看次数