webnode/oauth2-client

1.3.1 2024-09-26 09:58 UTC

README

webnode认证/OAuth2客户端

这可以被合作伙伴用作SDK,不应使用任何webnode库。

使用示例

实例化工厂

$factory = new \webnode\oauth2\Factory\WebnodeOAuth2Factory(
    new \webnode\oauth2\Configuration(
        'myClientId',
        'myClientSecret',
        'https://oauth2.webnode.com'
    )
);

生成单点登录URL

// generate SSO Link
$oauthApiService = $factory->createApi();
$ssoUrl = $oauthApiService->getAuthorizationUrlForUser(
    $userIdentifier,// obtained from gateway-api with project info or registration
    $redirectUrl // CMS or Administration (portal) URL, both can be obtained with same request as userIdentifier 
);
// now just redirect to $ssoUrl

生成单点登出URL

// generate SSO Link
$urlGenerator = $factory->createUrlGenerator();
$ssOutUrl = $urlGenerator->getSSOutUrl(); // this url is universal, since it just disables access to current session
// now just redirect to $ssOutUrl

从所有会话中登出用户

这可以在更改密码、禁用用户访问以违反规定等情况下使用。

// generate SSO Link
$oauthApiService = $factory->createApi();
$urlGenerator->revokeUserAccess($userIdentifier);
// now just redirect to $ssOutUrl