Esempio n. 1
0
        public IActionResult ExternalLogin(string provider, string returnUrl)
        {
            var          state = _stateHashingService.SetCookieAndReturnHash();
            string       redirect;
            ProviderType providerType;

            switch (provider.ToLower())
            {
            case "facebook":
                var facebookRedirect = this.FullUrlHelper(nameof(CallbackHandler), Name);
                redirect     = _loginLinkFactory.GetLink(ProviderType.Facebook, facebookRedirect, state, _settingsManager.Current.FacebookAppID);
                providerType = ProviderType.Facebook;
                break;

            case "google":
                var googleRedirect = this.FullUrlHelper(nameof(CallbackHandler), Name);
                redirect     = _loginLinkFactory.GetLink(ProviderType.Google, googleRedirect, state, _settingsManager.Current.GoogleClientId);
                providerType = ProviderType.Google;
                break;

            case "microsoft":
                var msftRedirect = this.FullUrlHelper(nameof(CallbackHandler), Name);
                redirect     = _loginLinkFactory.GetLink(ProviderType.Microsoft, msftRedirect, state, _settingsManager.Current.MicrosoftClientID);
                providerType = ProviderType.Microsoft;
                break;

            case "oauth2":
                var oauthRedirect = this.FullUrlHelper(nameof(CallbackHandler), Name);
                var linkGenerator = new OAuth2LoginUrlGenerator();
                var oauthClaims   = new List <string>(new[] { "openid", "email" });
                redirect     = linkGenerator.GetUrl(_settingsManager.Current.OAuth2LoginUrl, _settingsManager.Current.OAuth2ClientID, oauthRedirect, state, oauthClaims);
                providerType = ProviderType.OAuth2;
                break;

            default: throw new NotImplementedException($"The external login \"{provider}\" is not configured.");
            }

            var loginState = new ExternalLoginState {
                ProviderType = providerType, ReturnUrl = returnUrl
            };

            _externalLoginTempService.Persist(loginState);
            return(Redirect(redirect));
        }
Esempio n. 2
0
        public IActionResult ExternalLogin(string id)
        {
            var state = _stateHashingService.SetCookieAndReturnHash();

            switch (id.ToLower())
            {
            case "facebook":
                // This URL has to be specified in the Facebook developer console under "Valid OAuth Redirect URIs."
                var facebookRedirect = "https://localhost:44353/home/callbackfb";
                var facebookLink     = _loginLinkFactory.GetLink(ProviderType.Facebook, facebookRedirect, state);
                return(Redirect(facebookLink));

            case "google":
                // This URL has to specified in the Google Cloud console under Credentials -> OAuth 2.0 client ID's
                var googleRedirect = "https://localhost:44353/home/callbackgoogle";
                var googleLink     = _loginLinkFactory.GetLink(ProviderType.Google, googleRedirect, state);
                return(Redirect(googleLink));

            case "microsoft":
                // This URL has to specified in the Azure Portal under AD app registrations
                var msftRedirect = "https://localhost:44353/home/callbackmicrosoft";
                var msftLink     = _loginLinkFactory.GetLink(ProviderType.Microsoft, msftRedirect, state);
                return(Redirect(msftLink));

            case "msft":
                // This URL has to be specified as legal by whatever provider you're using
                var oauthRedirect = "https://localhost:44353/home/callbackoauth";
                var linkGenerator = new OAuth2LoginUrlGenerator();
                // choose the scope you're looking for
                var scopes    = new List <string>(new[] { "openid", "email" });
                var oauthLink = linkGenerator.GetUrl(_popIdentityConfig.OAuth2LoginUrl, _popIdentityConfig.OAuth2ClientID, oauthRedirect, state, scopes);
                return(Redirect(oauthLink));

            default: throw new NotImplementedException($"The external login \"{id}\" is not configured.");
            }
        }