小编Har*_*rry的帖子

如何在nodejs中对firebase-admin中的用户进行身份验证?

目前我正在nodejs上创建Firebase API.我想在nodejs上使用firebase-admin处理所有Firebase内容(例如身份验证).但是,如果没有客户端的Javascript Firebase SDK,在firebase-admin中通过nodejs对用户进行身份验证的正确方法是什么?在admin的官方文档中,我没有找到一个名为signInWithEmailAndPassword的函数(就像在客户端SDK上一样)用于nodejs.只有一个名为" getUserByEmail "的函数,但此函数不会检查用户是否输入了正确的密码.

这是我的表格:

<form class="sign-box" action="/login" method="post">

      <div class="form-group">
          <input id="username" name="username" type="text" class="form-control" placeholder="E-Mail"/>
      </div>
      <div class="form-group">
          <input id="password" name="password" type="password" class="form-control" placeholder="Password"/>
      </div>
      <button type="submit" class="btn btn-rounded">Sign in</button>

</form>
Run Code Online (Sandbox Code Playgroud)

提交表单后,我将值传递给nodejs中的API:

app.post('/login', urlencodedParser, function (req, res) {

    // getting the values

    response = {
        username: req.body.username,
        password: req.body.password

    };    

    // authenticate the user here, but how ?

});
Run Code Online (Sandbox Code Playgroud)

我的第一个想法是在客户端使用Firebase SDK使用signInWithEmailAndPassword登录并获取uid.一旦我有了UID,我想将UID发送到nodejs并调用函数createCustomToken并将生成的令牌(带有一些额外的声明)返回给客户端.一旦我得到令牌,我将使用函数signWithCustomToken(在客户端)来验证用户.这种方式是正确的还是有更好的方法?

authentication node.js firebase-admin

18
推荐指数
2
解决办法
7766
查看次数

如何更改 ASP.NET Core 中 userManager 的 dbContext?

我有两个数据库。

  • 应用程序数据库
  • 注册表数据库

application_db用于让应用程序开始工作并使用ApplicationDbContext

registry_db用于管理所有帐户。我想首先通过我的注册表服务创建一个帐户,然后将创建的帐户(信息较少)插入应用程序数据库。Registry_db正在使用RegistryDbContext

我已通过依赖项注入成功地将两个上下文(ApplicationDbContext 和RegistryDbContext)注入到我的注册表服务中。

我的启动看起来像这样:

services.AddCors();
services
.AddDbContext<RegistryDbContext>(
        options => options
        .UseNpgsql(
            Configuration.GetConnectionString("DefaultConnection"),
            b => b.MigrationsAssembly("Codeflow.Registry")
        )
    );

services
    .AddDbContext<ApplicationDbContext>(
    options => options
    .UseNpgsql(
            Configuration.GetConnectionString("ProductionConnection"),
        b => b.MigrationsAssembly("Codeflow.Registry")
    )
);
Run Code Online (Sandbox Code Playgroud)

在我的注册表服务中,我可以通过依赖项注入获取 userManager 并创建一个帐户。默认情况下,userManager 使用RegistryDbContext。通过注册表服务成功创建帐户后,我想在application_db(通过 ApplicationDbContext)创建相同的帐户。但我被这行代码困住了

// first I am creating the account in registry_db
var result = await _userManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{ 
    // once the account is created, I would like to create the …
Run Code Online (Sandbox Code Playgroud)

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

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