小编Rem*_*Rem的帖子

使用ASP.NET Core REST API在SPA(Angular 2)中进行社交注册

我已经实现了使用ASP.NET Core WebApi作为后端的简单Angular 2应用程序.对于身份验证,我添加了"/ login"路由,该路由生成JWT访问权限并刷新令牌,而令牌又由SPA存储在localStorage中并用于HTTP请求.

现在我想整合社交注册功能,以便用户可以使用Facebook按钮登录.从用户的角度来看,我想将其分为3个步骤:

  1. 点击Facebook注册按钮并重定向到Facebook网站(登录并确认我的应用程序请求).
  2. 点击确认并重定向到我的SPA所在/注册页面,其中他的名字已经从Facebook个人资料中填写
  3. 填写剩余的字段(如他最喜欢的玩具)并点击"完成注册"

在此注册后,如果用户再次通过facebook点击注册,他将被重定向到Facebook(如果他已经登录),他会自动重定向到服务器路由,检查这样的用户是否已经注册,如果是,则将其重定向到SPA主页

如何在我的应用程序中正确集成这样的工作流程?注意:我想在我的Angular2应用程序中执行身份验证和注册,而不是在不同的auth服务器上执行.

openid-connect oauth2 asp.net-core openiddict angular

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

强制C++程序在Visual Studio调试器中暂停

我在Windows下调试用MSVC编译的C++程序.我想研究与多线程相关的问题.所以我把ASSERT放在我的代码中,当程序到达ASSERT时,它会显示关于ASSERT(Standart [Abort],[Retry],[Ignore]窗口)的窗口,建议在调试器中暂停程序.我按[重试]按钮并暂停程序.但是当我按下按钮时,其他线程继续执行.所以问题是如何在达到某个点时立即停止程序以查看当时其他线程正在做什么?

c++ multithreading visual-c++ visual-studio-debugging

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

使用 LINQ select 返回异步任务

我想实现从数据库异步返回子项列表的函数。所以我写了一个函数:

    public async Task<IEnumerable<object>> GetFiles(int parentId)
    {
        var data = from file in DB.Files
                   where file.ParentId == parentId
                   select new { name = file.Name, id = file.Id };
        return data;
    }
Run Code Online (Sandbox Code Playgroud)

但是我可以看到一个警告:异步方法 lasks 'await' 操作符并将同步运行。如何将此函数重写为异步?

c# linq entity-framework-core .net-core asp.net-core

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

ASP.NET Core 管道多线程

ASP.NET Core 管道是否通过多线程处理请求?如果是,您如何配置线程数?而且,单例服务是否应该是线程安全的?

c# dependency-injection asp.net-core

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

IdentityServer4令牌签名验证

我有IdentityServer4生成签名的JWT令牌。在我的Web API中,我添加了身份验证中间件来验证这些令牌:

         app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
        {
            Authority = env.IsProduction() ? "https://www.example.com/api/" : "http://localhost/api/",
            AllowedScopes = { "WebAPI", "firm",
                IdentityServerConstants.StandardScopes.OpenId,
                IdentityServerConstants.StandardScopes.Profile },
            RequireHttpsMetadata = env.IsProduction(),
        });
Run Code Online (Sandbox Code Playgroud)

它运作完美。但是,我怀疑它没有验证jwt令牌的签名,因为没有配置用于验证令牌的公共密钥。如何配置令牌签名验证?

PS:我尝试通过这种方式使用UseJwtBearerAuthentication:

        var cert = new X509Certificate2("X509.pfx", "mypassword");
        var TokenValidationParameters = new TokenValidationParameters
        {
            ValidateIssuerSigningKey = true,
            ValidateIssuer = true,
            ValidIssuer = env.IsProduction() ? "https://www.example.com/api/" : "http://localhost/api/",
            IssuerSigningKey = new X509SecurityKey(cert),
        };
        app.UseJwtBearerAuthentication(new JwtBearerOptions
        {
            Authority = env.IsProduction() ? "https://www.wigwam3d.com/api/" : "http://localhost/api/",
            Audience = "WebAPI",
            RequireHttpsMetadata = env.IsProduction(),
            TokenValidationParameters = TokenValidationParameters
        });
Run Code Online (Sandbox Code Playgroud)

它也可以工作(我希望也可以验证令牌签名!),但是给了我另一个错误:

UserManager.GetUserAsync(HttpContext.HttpContext.User)
Run Code Online (Sandbox Code Playgroud)

返回null,在使用UseIdentityServerAuthentication时返回正确的用户

c# jwt asp.net-core identityserver4

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

QQuickView:在 C++ 中处理鼠标事件

我使用 QQuickView::beforeRendering 事件在 qml 控件下渲染我的 3d 模型。如果用户在任何 qml 控件之外单击,我想在 C++ 中处理鼠标事件/如何在 QQuickView::mousePressEvent 中发现鼠标在 qml 控件之外被按下?

c++ qt qml qtquick2 qtquickcontrols

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

tsconfig.json中的gulp-typescript和outFile选项

我正在使用gulpfile.js以这种方式编译我的tsconfig.json项目:

var ts = require('gulp-typescript');

var tsProject = ts.createProject('Modeler/tsconfig.json',
    { typescript: require('typescript') });

gulp.task('build:ts', function () {
    var tsResult = tsProject.src()
        .pipe(ts(tsProject));
    return tsResult.pipe(gulp.dest('wwwroot/app'));
});
Run Code Online (Sandbox Code Playgroud)

它工作正常,编译我的打字稿文件,并将js文件放入wwwroot/app文件夹

出现问题然后我希望TypeScript编译器使用outFile属性输出单个连接文件

{
  "compilerOptions": {
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": false,
    "sourceMap": true,
    "target": "es5",
    "module": "commonjs",
    "outFile": "modeler.js"
  },
  "exclude": [
    "node_modules",
    "wwwroot"
  ]  
}
Run Code Online (Sandbox Code Playgroud)

gulp任务会创建一个空输出文件,并创建*.js文件,其中包含*.ts文件旁边的内容.

如何在不污染源文件夹的情况下创建所需的输出文件?

typescript gulp typescript1.6 asp.net-core

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

在 IdentityServer4 的令牌请求中使用电子邮件

我使用带有 ASP.NET Core Identity 的 IdentityServer4 的 ROPC 流,我需要将用户名和密码发送到 /connect/token 端点以获取 access_token。

如何配置 IdentityServer4 以在 /connect/token 请求中接受用户名或电子邮件和密码?

PS:asp.net 核心:2.0.2 IdentityServer4:2.0.2

asp.net-core identityserver4

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

信号槽的语法糖

最近我在互联网上搜索了很好的信号槽库,并想知道为什么在地球上我们需要这么繁琐的语法来将成员方法连接到信号?

通常我们必须写这样的东西:

mySignal.connect(&MyClassName::myMethodName, this);
Run Code Online (Sandbox Code Playgroud)

或者像那样:

mySignal += std::bind(&MyClassName::myMethodName, this, std::placeholders::_1);
Run Code Online (Sandbox Code Playgroud)

有明显的重复和无意识的打字.在现代C++中是否有可能以例如C#方式实现此类功能:

mySignal += myMethodName
Run Code Online (Sandbox Code Playgroud)

并自动捕获指向成员函数的指针和来自上下文的指针?

c++ signals-slots c++11

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

在 nginx 反向代理后面配置 IdentityServer4

我在 nginx 反向代理后面有受 IdentityServer4 保护的 WebApi。代理传递配置:

    location /api/ {
        proxy_pass http://127.0.0.1:3110/;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_redirect off;
        proxy_buffering off;
        expires           0;
    }
Run Code Online (Sandbox Code Playgroud)

如果去https://www.example.com/api/.well-known/openid-configuration 它会返回我这个配置:

{
    "issuer": "http://www.example.com",
    "jwks_uri": "http://www.example.com/.well-known/openid-configuration/jwks",
    "authorization_endpoint": "http://www.example.com/connect/authorize",
    "token_endpoint": "http://www.example.com/connect/token",
    "userinfo_endpoint": "http://www.example.com/connect/userinfo",
    "end_session_endpoint": "http://www.example.com/connect/endsession",
    "check_session_iframe": "http://www.example.com/connect/checksession",
    "revocation_endpoint": "http://www.example.com/connect/revocation",
    "introspection_endpoint": "http://www.example.com/connect/introspect",
    "frontchannel_logout_supported": true,
    "frontchannel_logout_session_supported": true,
    "scopes_supported": [
        "openid",
        "profile",
        "roles",
        "WebAPI",
        "offline_access"
    ],
    "claims_supported": [
        "sub",
        "name",
        "family_name",
        "given_name",
        "middle_name",
        "nickname",
        "preferred_username",
        "profile",
        "picture",
        "website",
        "gender",
        "birthdate",
        "zoneinfo",
        "locale",
        "updated_at",
        "role",
        "firm"
    ],
    "grant_types_supported": [ …
Run Code Online (Sandbox Code Playgroud)

c# nginx asp.net-core identityserver4

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