pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    <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="hd5nlfh" id='aiNCI'><tfoot id='aiNCI'></tfoot><dl id='aiNCI'><fieldset id='aiNCI'></fieldset></dl></div>
    1. 使用 Laravel 5.4 和 Passport 進(jìn)行多重身份驗證

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

        <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="hftfnzx" 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 進(jìn)行多重身份驗證的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

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

                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.

                我設(shè)置了 3 個身份驗證防護(hù)/提供程序,總共 4 個.用戶、供應(yīng)商、管理員和 API

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

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

                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 種用戶類型,所以默認(rèn)為 API 提供者.

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

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

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

                推薦答案

                如果您仍然需要.

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

                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.

                對于多個守衛(wèi),您將不得不覆蓋一些代碼.

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

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

                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).

                您可能需要覆蓋其他內(nèi)容,但我進(jìn)行了測試并有效.

                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.

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

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

                相關(guān)文檔推薦

                Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標(biāo)不起作用)
                PHP PDO ODBC connection(PHP PDO ODBC 連接)
                Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術(shù)方法)
                php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                MSSQL PDO could not find driver(MSSQL PDO 找不到驅(qū)動程序)
                • <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="dtjp7bz" 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>
                          主站蜘蛛池模板: 结晶点测定仪-润滑脂滴点测定仪-大连煜烁 | 艾默生变频器,艾默生ct,变频器,ct驱动器,广州艾默生变频器,供水专用变频器,风机变频器,电梯变频器,艾默生变频器代理-广州市盟雄贸易有限公司官方网站-艾默生变频器应用解决方案服务商 | 大型冰雕-景区冰雕展制作公司,3D创意设计源头厂家-[赛北冰雕] | 北京宣传片拍摄_产品宣传片拍摄_宣传片制作公司-现像传媒 | 洁净实验室工程-成都手术室净化-无尘车间装修-四川华锐净化公司-洁净室专业厂家 | 包装机_厂家_价格-山东包装机有限公司 | 气动调节阀,电动调节阀,自力式压力调节阀,切断阀「厂家」-浙江利沃夫自控阀门 | 网优资讯-为循环资源、大宗商品、工业服务提供资讯与行情分析的数据服务平台 | 存包柜厂家_电子存包柜_超市存包柜_超市电子存包柜_自动存包柜-洛阳中星 | 海外整合营销-独立站营销-社交媒体运营_广州甲壳虫跨境网络服务 焊管生产线_焊管机组_轧辊模具_焊管设备_焊管设备厂家_石家庄翔昱机械 | 谈股票-今日股票行情走势分析-牛股推荐排行榜 | 杭州ROHS检测仪-XRF测试仪价格-百科 | 广州二手电缆线回收,旧电缆回收,广州铜线回收-广东益福电缆线回收公司 | 紧急泄压人孔_防爆阻火器_阻火呼吸阀[河北宏泽石化] | 不锈钢/气体/液体玻璃转子流量计(防腐,选型,规格)-常州天晟热工仪表有限公司【官网】 | 锂电混合机-新能源混合机-正极材料混料机-高镍,三元材料混料机-负极,包覆混合机-贝尔专业混合混料搅拌机械系统设备厂家 | 广州网站建设_小程序开发_番禺网站建设_佛山网站建设_粤联网络 | 一航网络-软件测评官网| 理化生实验室设备,吊装实验室设备,顶装实验室设备,实验室成套设备厂家,校园功能室设备,智慧书法教室方案 - 东莞市惠森教学设备有限公司 | 山东艾德实业有限公司| 利浦顿蒸汽发生器厂家-电蒸汽发生器/燃气蒸汽发生器_湖北利浦顿热能科技有限公司官网 | 压力控制器,差压控制器,温度控制器,防爆压力控制器,防爆温度控制器,防爆差压控制器-常州天利智能控制股份有限公司 | 骨密度检测仪_骨密度分析仪_骨密度仪_动脉硬化检测仪专业生产厂家【品源医疗】 | 筒瓦厂家-仿古瓦-寺庙-古建琉璃瓦-宜兴市古典园林建筑陶瓷厂有限公司 | 基业箱_环网柜_配电柜厂家_开关柜厂家_开关断路器-东莞基业电气设备有限公司 | 粘度计,数显粘度计,指针旋转粘度计 | 科普仪器菏泽市教育教学仪器总厂| 液压中心架,数控中心架,自定心中心架-烟台恒阳机电设计有限公司 行星搅拌机,双行星搅拌机,动力混合机,无锡米克斯行星搅拌机生产厂家 | 【MBA备考网】-2024年工商管理硕士MBA院校/报考条件/培训/考试科目/提前面试/考试/学费-MBA备考网 | 电伴热系统施工_仪表电伴热保温箱厂家_沃安电伴热管缆工业技术(济南)有限公司 | 医养体检包_公卫随访箱_慢病随访包_家签随访包_随访一体机-济南易享医疗科技有限公司 | 模具硅橡胶,人体硅胶,移印硅胶浆厂家-宏图硅胶科技 | 特种阀门-调节阀门-高温熔盐阀-镍合金截止阀-钛阀门-高温阀门-高性能蝶阀-蒙乃尔合金阀门-福建捷斯特阀门制造有限公司 | 电子万能试验机_液压拉力试验机_冲击疲劳试验机_材料试验机厂家-济南众标仪器设备有限公司 | 在线PH计-氧化锆分析仪-在线浊度仪-在线溶氧仪- 无锡朝达 | ge超声波测厚仪-电动涂膜机-电动划格仪-上海洪富| 首页|专注深圳注册公司,代理记账报税,注册商标代理,工商变更,企业400电话等企业一站式服务-慧用心 | 多功能干燥机,过滤洗涤干燥三合一设备-无锡市张华医药设备有限公司 | 防爆正压柜厂家_防爆配电箱_防爆控制箱_防爆空调_-盛通防爆 | 美国HASKEL增压泵-伊莱科elettrotec流量开关-上海方未机械设备有限公司 | 有机肥设备生产制造厂家,BB掺混肥搅拌机、复合肥设备生产线,有机肥料全部加工设备多少钱,对辊挤压造粒机,有机肥造粒设备 -- 郑州程翔重工机械有限公司 |