首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >利用aacotroneo/ Laravel - SAML 2包使用SAML的laravel和AZURE SSO

利用aacotroneo/ Laravel - SAML 2包使用SAML的laravel和AZURE SSO
EN

Stack Overflow用户
提问于 2022-07-11 15:22:43
回答 1查看 320关注 0票数 0

我正在我的Laravel应用程序中使用aacotroneo/laravel- SAML 2包尝试实现针对Azure AD的SAML身份验证。我配置了IDP设置,microsoft登录页面正确显示。问题是我无法从Azure那里获取用户信息。我按照这个问题的答案中的说明Azure Active Directory SSO with Laravel修改了文件app/Providers/SAML2ServiceProvider.php中的代码,添加了以下几行:

代码语言:javascript
运行
复制
public function boot()
    {
        Event::listen('Aacotroneo\Saml2\Events\Saml2LogoutEvent', function ($event) {
            if (session_status() !== PHP_SESSION_ACTIVE) {
                session_start();
            }
            unset($_SESSION["id"]);
            session_destroy();
        });

        Event::listen('Aacotroneo\Saml2\Events\Saml2LoginEvent', function (Saml2LoginEvent $event) {
            $messageId = $event->getSaml2Auth()->getLastMessageId();
            // Add your own code preventing reuse of a $messageId to stop replay attacks
            if (session_status() == PHP_SESSION_ACTIVE) {
                session_start();
            }
            $user = $event->getSaml2User();
            Log::info("COOKIE_SAML ACTIVATED");
            $_COOKIE["COOKIE_SAML"] = 1;

            $userData = [
                'id' => $user->getUserId(),
                'attributes' => $user->getAttributes(),
                'assertion' => $user->getRawSamlAssertion()
            ];

            Log::info(json_encode($userData));

            $inputs = [
                'sso_user_id'  => self::getValue($user->getUserId()),
                // 'username'     => $user->getAttribute('http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name'),
                'email'        => self::getValue($user->getAttribute('http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name')),
                'first_name'   => self::getValue($user->getAttribute('http://schemas.microsoft.com/identity/claims/displayname')),
                'last_name'    => self::getValue($user->getAttribute('http://schemas.microsoft.com/identity/claims/displayname')),
            ];

            $user = UserAdecco::where('sso_user_id', $inputs['sso_user_id'])->where('email', $inputs['email'])->first();
            if (!$user) {
                $res = UserAdecco::store($inputs);
                if ($res['status'] == 'success') {
                    $user  = $res['data'];
                    $_SESSION["id"] = $user->id;
                    // Auth::guard('web')->login($user);
                } else {
                    Log::info('SAML USER Error ' . $res['messages']);
                }
            } else {
                $_SESSION["id"] = $user->id;
                // Auth::guard('web')->login($user);
            }
        });
    }

但是,这段代码似乎根本没有被执行。结果是,当我登录时,什么都不会发生,用户也不会登录到Laravel应用程序中。我遗漏了什么?

EN

回答 1

Stack Overflow用户

发布于 2022-07-12 21:42:59

我发现了这个问题,服务提供者需要在config/app.php中注册才能工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72940919

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档