public PSADApplication CreateApplication(CreatePSApplicationParameters createParameters)
{
IList<PasswordCredential> passwordCredentials = createParameters.PasswordCredentials != null
? createParameters.PasswordCredentials.Select(psCredential => psCredential.ToGraphPasswordCredential()).ToList()
: null;
IList<KeyCredential> keyCredentials = createParameters.KeyCredentials != null
? createParameters.KeyCredentials.Select(psCredential => psCredential.ToGraphKeyCredential()).ToList()
: null;
ApplicationCreateParameters graphParameters = new ApplicationCreateParameters
{
DisplayName = createParameters.DisplayName,
Homepage = createParameters.HomePage,
IdentifierUris = createParameters.IdentifierUris,
ReplyUrls = createParameters.ReplyUrls,
AvailableToOtherTenants = createParameters.AvailableToOtherTenants,
PasswordCredentials = passwordCredentials,
KeyCredentials = keyCredentials
};
try
{
return GraphClient.Applications.Create(graphParameters).ToPSADApplication();
}
catch (GraphErrorException ce)
{
if (ce.Response.StatusCode == HttpStatusCode.Forbidden)
{
AADObject currentUser = GraphClient.Objects.GetCurrentUser();
if (currentUser != null && string.Equals(currentUser.UserType, "Guest", StringComparison.InvariantCultureIgnoreCase))
{
throw new InvalidOperationException(ProjectResources.CreateApplicationNotAllowedGuestUser);
}
}
throw;
}
}