标签: katana

推荐用于为owin身份验证实现自定义身份验证提供程序

我需要通过LinkedIn,Vkontakte和其他没有提供商的社交网络对用户进行身份验证.

我成功地通过以下方式创建自定义身份验证提供程序:

  1. Katana源代码中获取Facebook提供商的代码.
  2. 将所有"Facebook"更改为"Vkontakte"(只需找到并替换).
  3. 自定义[provider_name]AuthenticatedContext类,[provider_name]AuthenticationHandler.ApplyResponseChallengeAsync()[provider_name]AuthenticationHandler.AuthenticateCoreAsync().

一切都运作良好,但只是想知道.许多代码都是重复的,没有实际的变化.有没有办法使用任何标准的东西来构建自定义提供程序,而不仅仅是复制文件?

authentication owin katana

7
推荐指数
1
解决办法
3083
查看次数

客户端证书映射自托管Owin端点中的身份验证

是否有可能(如果是,如何?)配置自托管owin端点以使用A/D的客户端证书映射身份验证?IIS具有此功能链接,但到目前为止,我还没有找到自托管端点的等效项.

尽管如此(考虑到这种方法可能不是100%万无一失),我可以通过使用authenticationSchemeSelectorDelegate和OWIN的组合来完成两个步骤.

这将选择适当的AuthenticationScheme(允许包含证书的请求,否则推迟到NTLM身份验证)

public void Configuration(IAppBuilder appBuilder)
{
    var listener = (HttpListener)appBuilder.Properties[typeof(HttpListener).FullName];
    listener.AuthenticationSchemeSelectorDelegate += AuthenticationSchemeSelectorDelegate;
}

private AuthenticationSchemes AuthenticationSchemeSelectorDelegate(HttpListenerRequest httpRequest)
{
    if (!httpRequest.IsSecureConnection) return AuthenticationSchemes.Ntlm;
    var clientCert = httpRequest.GetClientCertificate();
    if (clientCert == null) return AuthenticationSchemes.Ntlm;
    else return AuthenticationSchemes.Anonymous;
}
Run Code Online (Sandbox Code Playgroud)

这将读取cert的内容并相应地填充"server.User"环境变量

public class CertificateAuthenticator
{
    readonly Func<IDictionary<string, object>, Task> _appFunc;

    public CertificateAuthenticator(Func<IDictionary<string, object>, Task> appFunc)
    {
        _appFunc = appFunc;
    }

    public Task Invoke(IDictionary<string, object> environment)
    {
        // Are we authenticated already (NTLM)
        var user = environment["server.User"] as IPrincipal;
        if …
Run Code Online (Sandbox Code Playgroud)

c# ssl active-directory owin katana

7
推荐指数
1
解决办法
3615
查看次数

OWIN/Katana和Mono之间的区别

我遇到了OWIN和Katana,我现在正试图了解这是什么.据我所知,它只是试图将Web应用程序与Web主机分开.

所以它基本上说当你构建一个ASP.NET MVC Web应用程序时,你在部署Web应用程序时绑定到IIS.使用OWIN/Katana你没有那个问题.这就是我从中理解的,这是正确的吗?

如果是这样,那么为什么我想在我的项目中使用OWIN/Katana时,我只需使用"mod_mono"将我的ASP.NET Web应用程序部署到NGINX,Apache等服务器上.

因为这基本上是OWIN项目的目标吗?但是我觉得将OWIN/Katana实现到我的Web应用程序然后只是简单地使用MVC 的Web API然后将其部署到Mono环境就更麻烦了.如果我愿意,我甚至可以在Linux中运行它.

所以什么时候应该选择OWIN/Katana而不是Mod Mono?它到底真的有所作为吗?

c# asp.net mono owin katana

7
推荐指数
0
解决办法
3109
查看次数

使IIS通过Owin管道开始响应请求的过程是什么?

如果在Visual Studio 2013中创建一个空的ASP.NET Web应用程序项目,请打开包管理器控制台并安装包Microsoft.Owin.Host.SystemWeb

添加具有配置(IAppBuilder应用程序)方法的Startup类,例如:

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.Run(context => context.Response.WriteAsync("hello"));
    }
}
Run Code Online (Sandbox Code Playgroud)

然后运行,你会看到hello出现在浏览器中.但是,你看一下这个项目,没有任何文件的变化,即web.config,它表明正在使用Owin管道.更重要的是,如果您有Startup类但不安装Microsoft.Owin.Host.SystemWeb包,则不会运行Startup的Configuration方法.

我怀疑有一个自定义模块和处理程序参与使所有这些发生,但无法找到任何有关它的文档.我能够找到的唯一能够轻微触及这个主题的是这个.

如何通过引用一些dll来改变处理请求的方式?

c# asp.net iis owin katana

7
推荐指数
2
解决办法
1483
查看次数

如何对使用OWIN Cookie Authenthication的代码进行单元测试

我了解到OWIN有一个很棒的Microsoft.Owin.Testing库,可以让你在内存中测试你的web应用程序.但是,在访问编写测试代码复杂的资源之前,我的站点需要身份验证.

使用Microsoft.Owin.Testing时,是否有一种方便的"模拟"身份验证方法?

我希望我的单元测试不需要进入进程外STS,我宁愿不需要编写以编程方式登录内存中STS的代码(例如Thinktecture.IdentityServer.v3).

我想出的最简单的解决方案是禁用单元测试的认证代码,其中我不是粉丝.

我正在使用OpenID Connect和Cookie身份验证.这是一个包含的例子.需要为实际服务器填写OpenId Connect的配置字符串.

[Test]
public async void AccessAuthenthicatedResourceTest()
{
    const string ClientId = "";
    const string RedirectUri = "";
    const string Authority = "";

    TestServer server = TestServer.Create(
        app =>
            {
                //Configure Open ID Connect With Cookie Authenthication
                app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
                app.UseCookieAuthentication(new CookieAuthenticationOptions());
                app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
                    {
                    ClientId = ClientId,
                    RedirectUri = RedirectUri,
                    Authority = Authority
                    });

                // Requires Authentication
                app.Use(
                    async ( context, next ) =>
                        {
                            var user = context.Authentication.User;
                            if ( user == null …
Run Code Online (Sandbox Code Playgroud)

.net c# unit-testing owin katana

7
推荐指数
1
解决办法
1648
查看次数

Web Api 2 HttpContext或HttpActionContext

以下两种通过AuthorizeAttribute实现访问原理的方法有什么区别?

使用HttpContext:

protected override bool IsAuthorized(HttpActionContext actionContext)
{
    return HttpContext.Current.User.IsInRole("DemoRole");
}
Run Code Online (Sandbox Code Playgroud)

使用HttpActionContext:

protected override bool IsAuthorized(HttpActionContext actionContext)
{
    return actionContext.RequestContext.Principal.IsInRole("DemoRole");
}
Run Code Online (Sandbox Code Playgroud)

owin katana asp.net-web-api2

7
推荐指数
1
解决办法
2395
查看次数

为什么我得到SecurityTokenSignatureKeyNotFoundException?

当我尝试将此JWT(由Azure移动服务发布)作为HTTP标头/授权/承载令牌传递时:

Header:
{
    "alg": "HS256", 
    "typ": "JWT", 
    "kid": "0"
}
Claims:
{
    "ver": 2, 
    "aud": "Facebook", 
    "iss": "urn:microsoft:windows-azure:zumo", 
    "urn:microsoft:credentials": "pYK8b5...", 
    "exp": 1436730730, 
    "uid": "Facebook:10000xxxxxxxxxx"
}
Run Code Online (Sandbox Code Playgroud)

进入我的ASP.NET WEB API配置:

const string issuer = "urn:microsoft:windows-azure:zumo";
byte[] mobileServicesSecret = TextEncodings.Base64Url.Decode(ConfigurationManager.AppSettings["as:SecretKey"]);

app.UseJwtBearerAuthentication(
    new JwtBearerAuthenticationOptions
    {
      AuthenticationMode = AuthenticationMode.Active,
      AllowedAudiences = new[] { "Facebook" },
      IssuerSecurityTokenProviders = new IIssuerSecurityTokenProvider[]
              {
                  new SymmetricKeyIssuerSecurityTokenProvider(issuer,  mobileServicesSecret)
              }
    });
Run Code Online (Sandbox Code Playgroud)

我明白了:

System.IdentityModel.Tokens.Jwt.dll中出现'System.IdentityModel.Tokens.SecurityTokenSignatureKeyNotFoundException'类型的第一次机会异常

我怀疑这是因为"孩子"财产的存在?

编辑:使用这个https://github.com/Magenic/JWTvalidator/tree/master/JwtValidator/JwtValidator ,可以验证JWT,所以它没有错.但我真的想用OWIN/Katana.

c# jwt asp.net-web-api katana

7
推荐指数
1
解决办法
1613
查看次数

IdentityServer3:某些声明未从身份服务器返回

上下文: 我使用ASP.NET MVC和OWIN自托管主机.以下是其他配置/设置.

在我的客户端的身份服务器中(注意AllowedScopes设置):

public static class InMemoryClientSource
{
    public static List<Client> GetClientList()
    {
        return new List<Client>()
        {
            new Client()
            {
                ClientName = "Admin website",
                ClientId = "admin",
                Enabled = true,
                Flow = Flows.Hybrid,
                ClientSecrets = new List<Secret>()
                {
                    new Secret("admin".Sha256())
                },
                RedirectUris = new List<string>()
                {
                    "https://admin.localhost.com/"
                },
                PostLogoutRedirectUris = new List<string>()
                {
                    "https://admin.localhost.com/"
                },
                AllowedScopes = new List<string> {
                    Constants.StandardScopes.OpenId,
                    Constants.StandardScopes.Profile,
                    Constants.StandardScopes.Email,
                    Constants.StandardScopes.Roles
                }
            }
        };
    }
}
Run Code Online (Sandbox Code Playgroud)

以下是范围:

public static class …
Run Code Online (Sandbox Code Playgroud)

asp.net asp.net-mvc owin katana identityserver3

7
推荐指数
2
解决办法
6972
查看次数

Identity Server 3 Facebook登录获取电子邮件

身份服务器已实施且运行良好.谷歌登录正在运行,并返回多项索赔,包括电子邮件.

Facebook登录正常,我的应用程序正在运行,并在新用户登录时请求电子邮件权限.

问题是我无法从oauth端点返回电子邮件,我似乎无法找到access_token来手动请求用户信息.我所拥有的只是从facebook登录端点返回的"代码".

这是IdentityServer设置.

var fb = new FacebookAuthenticationOptions
            {
                AuthenticationType = "Facebook",
                SignInAsAuthenticationType = signInAsType,
                AppId = ConfigurationManager.AppSettings["Facebook:AppId"],
                AppSecret = ConfigurationManager.AppSettings["Facebook:AppSecret"]
            };

            fb.Scope.Add("email");

            app.UseFacebookAuthentication(fb);
Run Code Online (Sandbox Code Playgroud)

当然我已经定制了AuthenticateLocalAsync方法,但我收到的声明只包括名称.没有电子邮件声明

通过身份服务器的源代码挖掘,我意识到有一些声称要转换facebook声明的事情,所以我扩展了该类调试它,看看它是否正在剥离任何声明,但事实并非如此.

我也看了fiddler的http调用,我只看到以下内容(道歉,因为代码格式化在url上不起作用.我试图将查询字符串格式化为自己的行,但它没有采取)

  1. (facebook.com)

    / dialog/oauth?response_type = code&client_id = xxx&redirect_uri = https%3A%2F%2Fidentity.[site] .com%2Fid%2Fsignin-facebook&scope = email&state = xxx

  2. (facebook.com)

    /login.php?skip_api_login = 1&api_key = xxx&signed_next = 1&next = https%3A%2F%2Fwww.facebook.com%2Fv2.7%2Fdialog%2Foauth%3Fredirect_uri%3Dhttps%253A%252F%252Fidentity.[site]. COM%252Fid%252Fsignin-的Facebook%26state%3Dxxx%26scope%3Demail%26response_type%3Dcode%26client_id%3Dxxx%26ret%3Dlogin%26logger_id%3Dxxx&cancel_url = HTTPS%3A%2F%2Fidentity.[站点] .COM%2Fid%2Fsignin- facebook%3Ferror%3Daccess_denied%26error_code%3D200%26error_description%3DPermissions%2Berror%26error_reason%3Duser_denied%26state%3Dxxx%23_%3D_&display = page&locale = en_US&logger_id = xxx

  3. (facebook.com)

    POST/cookie/consent /?pv = 1&dpr = 1 HTTP/1.1

  4. (facebook.com)

    /login.php?login_attempt = 1&next = https%3A%2F%2Fwww.facebook.com%2Fv2.7%2Fdialog%2Foauth%3Fredirect_uri%3Dhttps%253A%252F%252Fidentity.[site] .com%252Fid%252Fsignin- facebook%26state%3Dxxx%26scope%3Demail%26response_type%3Dcode%26client_id%3Dxxx%26ret%3Dlogin%26logger_id%3Dxxx&lwv = …

facebook-graph-api oauth-2.0 facebook-login katana identityserver3

7
推荐指数
1
解决办法
1737
查看次数

如何在没有IAppBuilder的情况下向Owin添加中间件

我目前正在构建一个包含几个OWIN中间件的库.这些中间件应按特定顺序执行.在OWIN的第一个版本中,有一个IAppBuilder界面.但是,IAppBuilder它不再是OWIN的一部分,而是Microsoft.Owin的一部分.我不想强迫我的用户依赖Microsoft.Owin.

在不使用Microsoft.Owin的情况下,将中间件添加到OWIN管道的首选方法是什么?

owin katana

7
推荐指数
1
解决办法
336
查看次数