相关疑难解决方法(0)

ASP.NET核心中的OAuth授权服务

在Web API 2中,您曾经能够通过中间件设置OAuth授权服务器来创建端点以发出令牌,如下所示:

//Set up our auth server options.
var OAuthServerOptions = new OAuthAuthorizationServerOptions()
            {
                AllowInsecureHttp = true,
                TokenEndpointPath = new PathString("/token"),
                AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
                Provider = new SimpleAuthorizationServerProvider()
            };

 // Sets up the token issue endpoint using the options above
 app.UseOAuthAuthorizationServer(OAuthServerOptions);
Run Code Online (Sandbox Code Playgroud)

也许我错过了它,但我想弄清楚如何在ASP.NET Core中做到这一点.我查看了源代码(https://github.com/aspnet/Security),但我真的没有看到类似的东西.有没有新的方法来实现这一目标?我是否需要创建一个控制器并自己完成?

我看到如何通过中间件设置OAuth身份验证,但这涉及我从API发出声明的授权部分.

asp.net oauth asp.net-core-mvc asp.net-core

56
推荐指数
1
解决办法
3万
查看次数

无法从'Microsoft.IdentityModel.Tokens.SymmetricSecurityKey'转换为'Microsoft.IdentityModel.Tokens.SigningCredentials'

在遵循教程 使用Web API和Jwt创建具有身份验证的RESTful API时,我无法让CustomJwtFormat类编译:

using System.IdentityModel.Tokens;
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.DataHandler.Encoder;
using Thinktecture.IdentityModel.Tokens;

namespace BooksAPI.Identity
{    
    public class CustomJwtFormat : ISecureDataFormat<AuthenticationTicket>
    {
        private static readonly byte[] _secret =              
             TextEncodings.Base64Url.Decode(ConfigurationManager.AppSettings["secret"]);
        private readonly string _issuer;

        public CustomJwtFormat(string issuer)
        {
            _issuer = issuer;
        }

        public string Protect(AuthenticationTicket data)
        {
            if (data == null)
                throw new ArgumentNullException(nameof(data));

            var signingKey = new HmacSigningCredentials(_secret);
            var issued = data.Properties.IssuedUtc;
            var expires = data.Properties.ExpiresUtc;

            return new JwtSecurityTokenHandler().WriteToken(
               new JwtSecurityToken( _issuer, null, data.Identity.Claims,
                   issued.Value.UtcDateTime, expires.Value.UtcDateTime, signingKey));
        } …
Run Code Online (Sandbox Code Playgroud)

oauth-2.0 asp.net-web-api owin asp.net-identity

8
推荐指数
2
解决办法
6166
查看次数

无法解析符号'Owin'

我目前正在尝试在AngularJS单页面应用程序中实现AspNet.Identity身份验证.奇怪的是,在我的ApplicationUserManager类中,我想使用Microsoft.Owin和Microsoft.AspNet.Identity.Owin但在这两种情况下我都得到一个"无法解析符号'Owin'"的错误消息.

有谁知道发生了什么?我已将依赖项包含在我的project.json中并下载了这些包.ApplicationUserManager类的简化版本是这样的:

using Matimez.Models;
using Matimez.Models.Users;
using Microsoft.AspNet.Identity.Owin;  //Error message
using Microsoft.Owin;                  //Error message
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;


public class ApplicationUserManager : UserManager<NewUser>
{ 
    public ApplicationUserManager(IUserStore<NewUser> store)
    : base(store)
        {
        }

public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context)
{
    var appDbContext = context.Get<MyAppContext>();
    var appUserManager = new ApplicationUserManager(new UserStore<NewUser>(appDbContext));

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

以下是我的project.json中的依赖项,如下所示:

  "dependencies": {
   "EntityFramework": "7.0.0-beta4",
   "EntityFramework.Commands": "7.0.0-beta4",
   "EntityFramework.SqlServer": "7.0.0-beta4",
   "MyApp.Models": "1.0.0-*",
   "MyApp.Services": "1.0.0-*",
   "Microsoft.AspNet.Diagnostics": "1.0.0-beta4",
   "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta4",
   "Microsoft.AspNet.Identity": "3.0.0-beta4",
   "Microsoft.AspNet.Mvc": "6.0.0-beta4",
   "Microsoft.AspNet.Server.IIS": "1.0.0-beta4",
   "Microsoft.AspNet.Server.WebListener": "1.0.0-beta4",
   "Microsoft.AspNet.StaticFiles": "1.0.0-beta4", …
Run Code Online (Sandbox Code Playgroud)

c# owin asp.net-identity

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