- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我的目标是使用 C# 的 CSP 全局管理员帐户在 Azure Active Directory 中为我的租户创建应用程序。
因为它是通过 PowerShell 命令工作的。
Login-AzureRmAccount ==> CSP Global admin credentials
Select-AzureRmSubscription -TenantId "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx(Enter your Customer Microsoft ID)" ==> Select a tenant where I want to create application
$password = ConvertTo-SecureString "SomePass@123" -asplaintext -force
New-AzureRmADApplication -DisplayName "MyApp" -HomePage "http://MyApp" -IdentifierUris "http://MyApp" -Password $password ==> Application created in the above mentioned tenants account.
请帮助我在 C# 中做同样的事情。
最佳答案
public static string postRequest(string url, string access_token, string data)
{
byte[] buffer = null;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "post";
request.ContentType = "application/json";
request.Headers.Add("Authorization", "Bearer " + access_token);
//request.Headers.Add("other header", "it's value");
if (data != null)
buffer = Encoding.UTF8.GetBytes(data);
else
buffer = Encoding.UTF8.GetBytes("");
request.ContentLength = buffer.Length;
request.GetRequestStream().Write(buffer, 0, buffer.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
return response.StatusCode + " " + reader.ReadToEnd();
}
}
public class PasswordCredential
{
public string startDate;
public string endDate;
public string keyId;
public string value;
}
public class AppConfiguration
{
public bool availableToOtherTenants;
public string displayName;
public string homepage;
public List<string> identifierUris = new List<string>();
public List<PasswordCredential> passwordCredentials = new List<PasswordCredential>();
}
static void Main(string[] args)
{
string tenantId = @"customer tenant id";
string resource = @"https://graph.windows.net/";
string clientId = @"1950a258-227b-4e31-a9cf-717495945fc2";
string returnUri = @"urn:ietf:wg:oauth:2.0:oob";
var context = new AuthenticationContext("https://login.microsoftonline.com/" + tenantId);
var uri = new Uri(returnUri);
var platformParams = new PlatformParameters(PromptBehavior.Always);
var authResult = context.AcquireTokenAsync(resource, clientId, uri, platformParams).Result;
var accessToken = authResult.AccessToken;
var url = @"https://graph.windows.net/{customer_tenant_id}/applications?api-version=1.6";
var passwordCredential = new PasswordCredential();
passwordCredential.startDate = DateTime.UtcNow.ToString("yyyy-MM-ddThh:mm:ssZ");
passwordCredential.endDate = DateTime.UtcNow.AddYears(1).ToString("yyyy-MM-ddThh:mm:ssZ");
passwordCredential.keyId = Guid.NewGuid().ToString();
passwordCredential.value = "TestPassword1.";
var appConfiguration = new AppConfiguration();
appConfiguration.availableToOtherTenants = false;
appConfiguration.displayName = "MyApp";
appConfiguration.homepage = "Https://MyApp";
appConfiguration.identifierUris.Add("https://MyApp");
appConfiguration.passwordCredentials.Add(passwordCredential);
var body = JsonConvert.SerializeObject(appConfiguration);
//Console.WriteLine(body);
var result = postRequest(url, accessToken, body);
Console.WriteLine(result);
Console.ReadLine();
}
我使用 ADAL、Newtonsoft.Json 和 HttpWebRequest 快速为您创建了一个示例。您可以先尝试使用此代码片段。
Update: It is not suggested to hardcode your username and password. If you enable MFA, you may not able to get a token. If MFA is disabled, you can try with the follwoing code snippet:
string userName = @"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4d353535350d3535353563222320242e3f223e222b39632e2220" rel="noreferrer noopener nofollow">[email protected]</a>";
string passWord = @"password";
var context = new AuthenticationContext("https://login.microsoftonline.com/tenant_id");
result = context.AcquireTokenAsync(
resource,
clientid,
new UserPasswordCredential(userName, passWord)).Result;
关于c# - 如何使用 CSP 全局管理员凭据在 Azure AD 中为我的租户注册应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55609587/
2 个不同的租户(租户 A 中的订阅 A 和租户 B 中的订阅 B) 我们在 Azure 云中有一个订阅,并且我们已经设置了 Azure Keyvault。我们可以在那里创建 key 并使用其中一个
如何在代码中配置 Windows Azure Active Directory 租户? 我希望能够允许用户访问我的 Multi-Tenancy SaaS 应用程序、注册我的服务并为其配置 Azure
我阅读了有关 headless 应用程序如何通过 Azure 进行身份验证的各种文章。我对术语有点困惑。在此sample code ,它说它需要一个 Azure AD 租户帐户。 我的理解是Azure
背景:我正在使用 Django 开发我的第一个 Multi-Tenancy 应用程序。我已经成功按照 https://github.com/tomturner/django-tenants 给出的教程
我正在尝试让 Microsoft 验证我的应用。第一步是成为微软合作伙伴,但我不知道如何登录? 当我尝试创建 Azure AD 租户时,我被告知我没有权限(即使我拥有该帐户)。 我无法使用用于登录 A
我开始学习 Microsoft Azure,但我陷入困境谁能详细告诉我 Microsoft 帐户、租户和订阅之间有什么区别? 最佳答案 当您说“Microsoft 帐户”时,这通常指个人 Micros
摘要:如何动态获取Microsoft用户的Tenant ID? 详细信息:我正在编写一个 Multi-Tenancy 应用程序(C# 和 .NET Core),我想使用它来创建订阅和 register
我正在尝试在澳大利亚区域创建 Azure B2C 租户,但在区域下拉列表中找不到澳大利亚。文档显示 Azure B2C 租户在所有位置都可用。我错过了什么吗? 最佳答案 基于Data residenc
我正在尝试在澳大利亚区域创建 Azure B2C 租户,但在区域下拉列表中找不到澳大利亚。文档显示 Azure B2C 租户在所有位置都可用。我错过了什么吗? 最佳答案 基于Data residenc
我正在尝试 ad-b2c,天哪,即使第一步结果也非常令人沮丧。无论如何,这是我的问题: 我的现有订阅有一个默认目录,该目录有自己的 mydefaultdirectory.onmicrosoft.com
我正在开发一个 ASP.NET MVC 应用程序,它必须访问 Office365 API。我使用了描述here为了获得仅应用程序的访问 token 。 现在,运行应用程序后,我进入 AAD 同意流程以
假设我购买了位于 Azure AD 租户 1(与资源林同义)中的 Multi-Tenancy 应用程序(HR 软件)。 我还购买了 Azure 租户 2 中另一家公司拥有的健康应用程序。 我不拥有租户
这是我的场景:新用户使用 Azure B2C 工作流程注册我们的 Web 应用程序。用户可以使用不同的身份提供商(Google、Microsoft、Amazon)进行注册。用户需要访问数据库。我想将他
我正在尝试删除我的 Azure AD 租户,但它显示: Directory has one or more applications. 我按照此处的步骤操作 https://support.micro
我有两个 B2C 租户。一种用于生产环境,另一种用于临时环境。我想将所有用户从生产租户迁移到暂存租户。我想定期这样做,用真实数据对临时环境进行测试。我知道我可以读取一个租户的所有用户并将其写入另一个租
Microsoft 的 UI 显示所有初始检查均已通过,他们可以删除此 Azure Active Directory 租户。随后出现消息称 Microsoft 实际上无法删除租户。我还能做些什么来真正
我正在尝试删除我的 Azure AD 租户,但它显示: Directory has one or more applications. 我按照此处的步骤操作 https://support.micro
我有两个 B2C 租户。一种用于生产环境,另一种用于临时环境。我想将所有用户从生产租户迁移到暂存租户。我想定期这样做,用真实数据对临时环境进行测试。我知道我可以读取一个租户的所有用户并将其写入另一个租
Microsoft 的 UI 显示所有初始检查均已通过,他们可以删除此 Azure Active Directory 租户。随后出现消息称 Microsoft 实际上无法删除租户。我还能做些什么来真正
有没有办法阻止用户登录到他们自己的 AAD 租户?例如,允许登录 contoso.onmicrosoft.com 但不允许登录 fabrikam.onmicrosoft.com。 我的客户有一个高度受
我是一名优秀的程序员,十分优秀!