久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <tfoot id='aiNCI'></tfoot>

  1. <legend id='aiNCI'><style id='aiNCI'><dir id='aiNCI'><q id='aiNCI'></q></dir></style></legend>
    • <bdo id='aiNCI'></bdo><ul id='aiNCI'></ul>

    <small id='aiNCI'></small><noframes id='aiNCI'>

    <i id='aiNCI'><tr id='aiNCI'><dt id='aiNCI'><q id='aiNCI'><span id='aiNCI'><b id='aiNCI'><form id='aiNCI'><ins id='aiNCI'></ins><ul id='aiNCI'></ul><sub id='aiNCI'></sub></form><legend id='aiNCI'></legend><bdo id='aiNCI'><pre id='aiNCI'><center id='aiNCI'></center></pre></bdo></b><th id='aiNCI'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='aiNCI'><tfoot id='aiNCI'></tfoot><dl id='aiNCI'><fieldset id='aiNCI'></fieldset></dl></div>
    1. 使用 Laravel 5.4 和 Passport 進行多重身份驗證

      Multi Auth with Laravel 5.4 and Passport(使用 Laravel 5.4 和 Passport 進行多重身份驗證)

        <tbody id='6Wzye'></tbody>

      <tfoot id='6Wzye'></tfoot>
      • <bdo id='6Wzye'></bdo><ul id='6Wzye'></ul>

          <legend id='6Wzye'><style id='6Wzye'><dir id='6Wzye'><q id='6Wzye'></q></dir></style></legend>
            <i id='6Wzye'><tr id='6Wzye'><dt id='6Wzye'><q id='6Wzye'><span id='6Wzye'><b id='6Wzye'><form id='6Wzye'><ins id='6Wzye'></ins><ul id='6Wzye'></ul><sub id='6Wzye'></sub></form><legend id='6Wzye'></legend><bdo id='6Wzye'><pre id='6Wzye'><center id='6Wzye'></center></pre></bdo></b><th id='6Wzye'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='6Wzye'><tfoot id='6Wzye'></tfoot><dl id='6Wzye'><fieldset id='6Wzye'></fieldset></dl></div>
            • <small id='6Wzye'></small><noframes id='6Wzye'>

                本文介紹了使用 Laravel 5.4 和 Passport 進行多重身份驗證的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我正在嘗試使用 Laravel Passport 設置多重身份驗證,但它似乎不支持它.我正在使用密碼授予來頒發令牌,這要求我傳遞想要訪問令牌的用戶的用戶名/密碼.

                I am trying to setup multi auth with Laravel Passport, but it doesn't seem to support it. I am using the Password Grant to issue tokens which requires me to pass username/password of the user wanting access tokens.

                我設置了 3 個身份驗證防護/提供程序,總共 4 個.用戶、供應商、管理員和 API

                I have 3 auth guards/providers setup, 4 in total. Users, Vendors, Admins and API

                其中 2 個 Auth 需要通行證訪問權限,因此每個用戶都需要能夠頒發令牌.但是 Passport 會自動采用 API 身份驗證提供程序,但我希望根據登錄的用戶進行更改..

                2 of the Auths need passport access, so each user needs to be able to issue tokens. But Passport automatically takes the API auth provider, but I want this to change based on which user is logging in.. If user does then the User provider and if its a vendor then the Vendor provider.

                但是 Passport 目前只支持 1 種用戶類型,所以默認為 API 提供者.

                But the way Passport currently only supports only 1 user type, so its defaulting to the API provider.

                有什么更好的方法嗎?或者我應該改用基于角色的身份驗證.

                Is there something better for this? or should I go with roles based authentication instead.

                推薦答案

                如果您仍然需要.

                我更喜歡使用角色,有一個很棒的插件:https://github.com/larapacks/授權

                I prefer go with roles, there is an amazing plugin for that: https://github.com/larapacks/authorization

                但如果您有某種需要,您可以按照以下步驟使用.

                But if you somehow needs that, you will be able to use following the steps bellow.

                對于多個守衛,您將不得不覆蓋一些代碼.

                For multi guards, you will have to overwrite some code.

                您不是加載 PassportServiceProvider,而是創建自己的并擴展 PassportServiceProvider 并覆蓋方法 makePasswordGrant.在此方法中,您將為自己的擴展存儲庫更改 Passport UserRepository.在用戶存儲庫上,您必須將靜態模型配置更改為動態模型配置(我從請求屬性加載,但您可以從任何地方獲取).

                Instead of loading PassportServiceProvider, you create your own and extends the PassportServiceProvider and overwrites the method makePasswordGrant. On this method, you will change the Passport UserRepository for your own repository extended. On user repository you must to change the static model config for a dynamic one (I load from request attributes, but you can get from anywhere).

                您可能需要覆蓋其他內容,但我進行了測試并有效.

                You may have to overwrite something else, but I made a test and works.

                例如:

                PassportServiceProvider

                PassportServiceProvider

                namespace AppProviders;
                
                use LeagueOAuth2ServerAuthorizationServer;
                use LeagueOAuth2ServerGrantPasswordGrant;
                use LaravelPassportPassportServiceProvider as BasePassportServiceProvider;
                use LaravelPassportPassport;
                
                class PassportServiceProvider extends BasePassportServiceProvider
                {
                    /**
                     * Create and configure a Password grant instance.
                     *
                     * @return PasswordGrant
                     */
                    protected function makePasswordGrant()
                    {
                        $grant = new PasswordGrant(
                            $this->app->make(AppRepositoriesPassportUserRepository::class),
                            $this->app->make(LaravelPassportBridgeRefreshTokenRepository::class)
                        );
                
                        $grant->setRefreshTokenTTL(Passport::refreshTokensExpireIn());
                
                        return $grant;
                    }
                
                }
                

                用戶存儲庫

                namespace AppRepositories;
                
                use App;
                use IlluminateHttpRequest;
                use LeagueOAuth2ServerEntitiesClientEntityInterface;
                use LaravelPassportBridgeUserRepository;
                use LaravelPassportBridgeUser;
                use RuntimeException;
                
                class PassportUserRepository extends UserRepository
                {
                    /**
                     * {@inheritdoc}
                     */
                    public function getUserEntityByUserCredentials($username, $password, $grantType, ClientEntityInterface $clientEntity)
                    {
                        $guard = App::make(Request::class)->attributes->get('guard') ?: 'api';
                        $provider = config("auth.guards.{$guard}.provider");
                
                
                        if (is_null($model = config("auth.providers.{$provider}.model"))) {
                            throw new RuntimeException('Unable to determine user model from configuration.');
                        }
                
                
                        if (method_exists($model, 'findForPassport')) {
                            $user = (new $model)->findForPassport($username);
                        } else {
                            $user = (new $model)->where('email', $username)->first();
                        }
                
                
                        if (! $user ) {
                            return;
                        } elseif (method_exists($user, 'validateForPassportPasswordGrant')) {
                            if (! $user->validateForPassportPasswordGrant($password)) {
                                return;
                            }
                        } elseif (! $this->hasher->check($password, $user->password)) {
                            return;
                        }
                
                        return new User($user->getAuthIdentifier());
                    }
                }
                

                PS:對不起,我的英語不好.

                PS: Sorry my bad english.

                這篇關于使用 Laravel 5.4 和 Passport 進行多重身份驗證的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                PHP PDO ODBC connection(PHP PDO ODBC 連接)
                Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)
                • <bdo id='IFgXi'></bdo><ul id='IFgXi'></ul>
                  <tfoot id='IFgXi'></tfoot>
                    <legend id='IFgXi'><style id='IFgXi'><dir id='IFgXi'><q id='IFgXi'></q></dir></style></legend>
                    <i id='IFgXi'><tr id='IFgXi'><dt id='IFgXi'><q id='IFgXi'><span id='IFgXi'><b id='IFgXi'><form id='IFgXi'><ins id='IFgXi'></ins><ul id='IFgXi'></ul><sub id='IFgXi'></sub></form><legend id='IFgXi'></legend><bdo id='IFgXi'><pre id='IFgXi'><center id='IFgXi'></center></pre></bdo></b><th id='IFgXi'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='IFgXi'><tfoot id='IFgXi'></tfoot><dl id='IFgXi'><fieldset id='IFgXi'></fieldset></dl></div>

                    <small id='IFgXi'></small><noframes id='IFgXi'>

                            <tbody id='IFgXi'></tbody>
                          主站蜘蛛池模板: 18成人在线观看 | 午夜看片| 欧美成人精品在线 | 毛片视频免费观看 | 在线一区二区三区 | 日韩久久久一区二区 | 视频在线亚洲 | 国产激情在线 | 亚洲精品成人 | 日韩一区二区在线观看 | 成人国产精品免费观看 | 成人在线观看免费 | 亚洲 欧美 在线 一区 | 亚洲一区中文字幕 | 亚洲视频免费 | 久久逼逼 | 91麻豆精品国产91久久久久久 | 国产精品久久久久久久免费大片 | 欧美精品在线免费 | 午夜视频在线 | 国产乱码精品1区2区3区 | 国产亚洲人成a在线v网站 | 91视频在线观看 | 色悠悠久 | 国产三级国产精品 | 亚洲综合在线视频 | 亚洲福利 | 911精品美国片911久久久 | 亚洲精品久久久一区二区三区 | 神马久久久久久久久久 | 国产精品一区二区久久精品爱微奶 | 黄色在线免费观看视频网站 | 久久久久久久久久久久久久久久久久久久 | 91在线精品一区二区 | 国产精品99久久久久久动医院 | 日韩精品福利 | 一区在线播放 | 一区二区三区四区在线视频 | 精品国产乱码久久久久久牛牛 | 毛片一级网站 | 国产精品福利在线观看 |