dongtieshang5429
2016-09-06 17:51
浏览 102
已采纳

Yii2登录无密码验证

I am working on project that will use API of another application. So I won't validate password on my app, will do this via API request. I don't want to store users` passwords in db. Just check password by API.

How can I authenticate a user without login credentials?

图片转代码服务由CSDN问答提供 功能建议

我正在处理将使用其他应用程序的API的项目。 所以我不会在我的应用程序上验证密码,将通过API请求执行此操作。 我不想在db中存储用户的密码。 只需通过API检查密码即可。

如何在没有登录凭据的情况下对用户进行身份验证?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dtmooir3395 2016-09-06 18:32
    已采纳

    Login & Session in Yii 2 is managed by \yii\web\User class This class is accessible in the application life cycle via the \Yii::$app->user property.

    On successful authentication using your third-party provider you use the login() function using Yii::$app->user->login($identity)

    $identity should be an object of [IdentityInterface][4] usually the User ActiveRecord model implementing this interface

    Refer to the guide documentation on Authentication for full understanding on how authentication works in Yii2

    打赏 评论
  • doupao3662 2016-10-03 08:04

    In our app we are using a field auth_key related to a User Model and then we go to this link, find a user in database by this auth_key and make a login (or not if it is not found in database )

    public actionAuthLogin($auth_key){
      if(($user = User::findOne(['auth_key' => $auth_key])) 
            && \Yii:$app->user->login($user)){
         return $this->goHome();
      } else {
    
         throw new NotFoundHttpException()
      }
    
    }
    

    then

    /controller/auth-login?auth_key=should_be_in_database_ahsgdashdajsdg123mkasd
    
    打赏 评论

相关推荐 更多相似问题