예제 #1
0
        public async Task <IActionResult> CallbackOAuth()
        {
            var result = await _oAuth2JwtCallbackProcessor.VerifyCallback("https://localhost:44353/home/callbackoauth", _popIdentityConfig.OAuth2TokenUrl);

            if (!result.IsSuccessful)
            {
                return(Content(result.Message));
            }
            var list = $"id: {result.ResultData.ID}\r\nname: {result.ResultData.Name}\r\nemail: {result.ResultData.Email}";

            return(Content(list));
        }
예제 #2
0
        public async Task <IActionResult> CallbackHandler()
        {
            var loginState = _externalLoginTempService.Read();

            if (loginState == null)
            {
                var ip = HttpContext.Connection.RemoteIpAddress.ToString();
                await _securityLogService.CreateLogEntry((User)null, null, ip, "Temp auth cookie missing on callback", SecurityLogType.ExternalAssociationCheckFailed);

                return(View("ExternalError", Resources.Error + ": " + Resources.LoginBad));
            }
            var            redirectUri = this.FullUrlHelper(nameof(CallbackHandler), Name);
            CallbackResult result;

            switch (loginState.ProviderType)
            {
            case ProviderType.Facebook:
                result = await _facebookCallbackProcessor.VerifyCallback(redirectUri, _settingsManager.Current.FacebookAppID, _settingsManager.Current.FacebookAppSecret);

                break;

            case ProviderType.Google:
                result = await _googleCallbackProcessor.VerifyCallback(redirectUri, _settingsManager.Current.GoogleClientId, _settingsManager.Current.GoogleClientSecret);

                break;

            case ProviderType.Microsoft:
                result = await _microsoftCallbackProcessor.VerifyCallback(redirectUri, _settingsManager.Current.MicrosoftClientID, _settingsManager.Current.MicrosoftClientSecret);

                break;

            case ProviderType.OAuth2:
                result = await _oAuth2JwtCallbackProcessor.VerifyCallback(redirectUri, _settingsManager.Current.OAuth2TokenUrl, _settingsManager.Current.OAuth2ClientID, _settingsManager.Current.OAuth2ClientSecret);

                break;

            default:
                throw new Exception($"The external login type {loginState.ProviderType} has no callback handler.");
            }
            if (!result.IsSuccessful)
            {
                return(View("ExternalError", result.Message));
            }
            loginState.ResultData = result.ResultData;
            _externalLoginTempService.Persist(loginState);

            return(RedirectToAction("ExternalLoginCallback", new { returnUrl = loginState.ReturnUrl }));
        }