示例#1
0
        private void btnAuthenticate_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtApplicationID.Text.Length > 20
                    && txtSharedSecret.Text.Length > 20)
                {
                    btnAuthenticate.Text = "Authenticating...";
                    var appAuthInfo = new AppAuthInfo
                    {
                        ApplicationId = txtApplicationID.Text,
                        SharedSecret = txtSharedSecret.Text
                    };
                    if (txtEmail.Text.Contains("@") &&
                        txtEmail.Text.Contains(".") &&
                        txtPassword.Text.Length > 5)
                    {
                        AppAuthenticator.Initialize(appAuthInfo, GetAuthBaseUrl());
                        btnAuthenticate.Text = "Loading Scopes...";
                        panelAPI.Visible = true;
                        panelTenant.Visible = true;
                        var userAuthInfo = new UserAuthInfo {EmailAddress = txtEmail.Text, Password = txtPassword.Text};
                        _userInfo = UserAuthenticator.Authenticate(userAuthInfo, AuthenticationScope.Tenant);

                        panelTenant.Visible = true;

                        cbTenant.DataSource = _userInfo.AuthorizedScopes;

                        btnAuthenticate.Text = "Renew Authentication";
                    }
                    else
                    {
                        btnAuthenticate.Text = "Authenticate";
                        LogError(new Exception("Not enough User data entered for User Scope Authentication"));
                    }
                }
                else
                {
                   LogError(new Exception("Not enough Application data entered for Authentication"));
                }
            }
            catch (ApiException exc)
            {
                LogError(exc);
                btnAuthenticate.Text = "Authenticate";
            }
        }
示例#2
0
        private static AuthenticationProfile SetUserAuth(string response, AuthenticationScope scope, int?siteId = null)
        {
            var authenticationProfile = new AuthenticationProfile();

            authenticationProfile.AuthTicket = JsonConvert.DeserializeObject <AuthTicket>(response);
            authenticationProfile.AuthTicket.AuthenticationScope = scope;
            authenticationProfile.AuthTicket.SiteId = siteId;

            switch (scope)
            {
            case AuthenticationScope.Tenant:
                var tenantAdminUserAuthTicket = JsonConvert.DeserializeObject <TenantAdminUserAuthTicket>(response);
                authenticationProfile.UserProfile      = tenantAdminUserAuthTicket.User;
                authenticationProfile.AuthorizedScopes = (from t in tenantAdminUserAuthTicket.AvailableTenants select new Scope {
                    Id = t.Id, Name = t.Name
                }).ToList();
                if (tenantAdminUserAuthTicket.Tenant != null)
                {
                    authenticationProfile.ActiveScope = new Scope {
                        Id = tenantAdminUserAuthTicket.Tenant.Id, Name = tenantAdminUserAuthTicket.Tenant.Name
                    }
                }
                ;
                break;

            case AuthenticationScope.Developer:
                var devAccount = JsonConvert.DeserializeObject <DeveloperAdminUserAuthTicket>(response);
                authenticationProfile.UserProfile      = devAccount.User;
                authenticationProfile.AuthorizedScopes = (from t in devAccount.AvailableAccounts select new Scope {
                    Id = t.Id, Name = t.Name
                }).ToList();
                if (devAccount.Account != null)
                {
                    authenticationProfile.ActiveScope = new Scope {
                        Id = devAccount.Account.Id, Name = devAccount.Account.Name
                    }
                }
                ;
                break;
            }

            return(authenticationProfile);
        }
		private static AuthenticationProfile SetUserAuth(string response, AuthenticationScope scope, int? siteId = null)
        {
            var authenticationProfile = new AuthenticationProfile();

            authenticationProfile.AuthTicket = JsonConvert.DeserializeObject<AuthTicket>(response);
            authenticationProfile.AuthTicket.AuthenticationScope = scope;
            authenticationProfile.AuthTicket.SiteId = siteId;

            switch (scope)
            {
                case AuthenticationScope.Tenant:
                    var tenantAdminUserAuthTicket = JsonConvert.DeserializeObject<TenantAdminUserAuthTicket>(response);
                    authenticationProfile.UserProfile = tenantAdminUserAuthTicket.User;
                    authenticationProfile.AuthorizedScopes = (from t in tenantAdminUserAuthTicket.AvailableTenants select new Scope { Id = t.Id, Name = t.Name }).ToList();
                    if (tenantAdminUserAuthTicket.Tenant != null)
                        authenticationProfile.ActiveScope = new Scope { Id = tenantAdminUserAuthTicket.Tenant.Id, Name = tenantAdminUserAuthTicket.Tenant.Name };
                    break;
                case AuthenticationScope.Developer:
                    var devAccount = JsonConvert.DeserializeObject<DeveloperAdminUserAuthTicket>(response);
                    authenticationProfile.UserProfile = devAccount.User;
                    authenticationProfile.AuthorizedScopes = (from t in devAccount.AvailableAccounts select new Scope { Id = t.Id, Name = t.Name }).ToList();
                    if (devAccount.Account != null)
                        authenticationProfile.ActiveScope = new Scope { Id = devAccount.Account.Id, Name = devAccount.Account.Name };
                    break;
            }

            return authenticationProfile;
        }