Example #1
0
        public ExternalLoginViewModel GetData(int id)
        {
            var externalLoginVM = new ExternalLoginViewModel
            {
                Name = "Home",
                Url = "http://127.0.0.1",
                State = "CO"
            };

            switch (id)
            {
                case 1:
                    externalLoginVM = new ExternalLoginViewModel
                    {
                        Name = "Redmond",
                        Url = "http://microsoft.com",
                        State = "WA"
                    };
                    break;
                case 2:
                    externalLoginVM = new ExternalLoginViewModel
                    {
                        Name = "New York",
                        Url = "http://mhfi.com",
                        State = "NY"
                    };
                    break;
                default:
                    externalLoginVM = new ExternalLoginViewModel
                    {
                        Name = "Denver",
                        Url = "http://denverdevday.eventday.com",
                        State = "CO"
                    };
                    break;

            }
            return externalLoginVM;
        }
Example #2
0
        public IEnumerable<ExternalLoginViewModel> GetExternalLogins(string returnUrl, bool generateState = false)
        {
            IEnumerable<AuthenticationDescription> descriptions = Authentication.GetExternalAuthenticationTypes();
            List<ExternalLoginViewModel> logins = new List<ExternalLoginViewModel>();

            string state;

            if (generateState)
            {
                const int strengthInBits = 256;
                state = RandomOAuthStateGenerator.Generate(strengthInBits);
            }
            else
            {
                state = null;
            }

            foreach (AuthenticationDescription description in descriptions)
            {
                ExternalLoginViewModel login = new ExternalLoginViewModel
                {
                    Name = description.Caption,
                    Url = Url.Route("ExternalLogin", new
                    {
                        provider = description.AuthenticationType,
                        response_type = "token",
                        client_id = Startup.PublicClientId,
                        redirect_uri = new Uri(Request.RequestUri, returnUrl).AbsoluteUri,
                        state = state
                    }),
                    State = state
                };
                logins.Add(login);
            }

            return logins;
        }