我试图了解 ProviderSignInController 是做什么的,但我很难理解它。
因此,当我单击使用 facebook 登录时,我会转到 facebook 登录页面,然后在输入我的凭据后调用以下方法
org.springframework.social.connect.web.ProviderSignInController.oauth1Callback(String, NativeWebRequest)
/**
* Process the authentication callback from an OAuth 2 service provider.
* Called after the user authorizes the authentication, generally done once by having he or she click "Allow" in their web browser at the provider's site.
* Handles the provider sign-in callback by first determining if a local user account is associated with the connected provider account.
* If so, signs the local user in by delegating to {@link SignInAdapter#signIn(String, Connection, NativeWebRequest)}.
* If not, redirects the user to a signup page to create a new account with {@link ProviderSignInAttempt} context exposed in the HttpSession.
* @see ProviderSignInAttempt
* @see ProviderSignInUtils
*/
@RequestMapping(value="/{providerId}", method=RequestMethod.GET, params="code")
public RedirectView oauth2Callback(@PathVariable String providerId, @RequestParam("code") String code, NativeWebRequest request) {
try {
OAuth2ConnectionFactory<?> connectionFactory = (OAuth2ConnectionFactory<?>) connectionFactoryLocator.getConnectionFactory(providerId);
Connection<?> connection = connectSupport.completeConnection(connectionFactory, request);
return handleSignIn(connection, connectionFactory, request);
} catch (Exception e) {
logger.error("Exception while completing OAuth 2 connection: ", e);
return redirect(URIBuilder.fromUri(signInUrl).queryParam("error", "provider").build().toString());
}
}
我不明白的是它说通过首先确定本地用户帐户是否与连接的提供者帐户相关联来处理提供者登录回调。
在第二行中它说如果是这样,则通过委派给本地用户登录 {@link SignInAdapter#signIn(String, Connection, NativeWebRequest)}
我明白了。
但我无法理解这一行,如果没有,则将用户重定向到注册页面以创建一个新帐户,其中 {@link ProviderSignInAttempt} 上下文暴露在 HttpSession 中。
我现在在想,当我第一次尝试使用 facebook 登录时......连接存储库中将没有用户......所以每次我都会被重定向到注册页面。春季社交意味着您不必注册和使用 Facebook 凭据。
所以我不明白这一切背后的逻辑是什么。