public static AuthenticationProfile Authenticate(UserAuthInfo authInfo, AuthenticationScope scope, int? id = null) { var resourceUrl = GetResourceUrl(scope, id); var client = new HttpClient { BaseAddress = new Uri(AppAuthenticator.Instance.BaseUrl) }; var stringContent = JsonConvert.SerializeObject(authInfo); AppAuthenticator.AddHeader(client); var response = client.PostAsync(resourceUrl, new StringContent(stringContent, Encoding.UTF8, "application/json")).Result; ResponseHelper.EnsureSuccess(response); return SetUserAuth(response.Content.ReadAsStringAsync().Result, scope,null); }
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"; } }
public void SimpleAuthLoginTest() { var emailAddress = Mozu.Api.Test.Helpers.Environment.GetConfigValueByEnvironment("devOwnerEmail"); var password = Mozu.Api.Test.Helpers.Environment.GetConfigValueByEnvironment("devOwnerPassword"); var userAuthInfo = new UserAuthInfo { EmailAddress = emailAddress, Password = password }; var userInfo = UserAuthenticator.Authenticate(userAuthInfo, AuthenticationScope.Developer); Assert.IsNotNull(userInfo); Assert.IsNotNull(userInfo.AuthTicket); Assert.IsNotNull(userInfo.AuthTicket.AccessToken); if (userInfo.ActiveScope == null) { userInfo = UserAuthenticator.SetActiveScope(userInfo.AuthTicket, userInfo.AuthorizedScopes.First()); Assert.IsNotNull(userInfo); Assert.IsNotNull(userInfo.ActiveScope); } }