我在Publish the server project之后发布我的Azure应用服务(.Net后端)
曾经工作,但现在我不能让它工作了。当我在Visual Studio中单击发布时,它构建并说
"========== Publish: 1 succeeded, 0 failed, 0 skipped =========="
但是在之后打开的Web浏览器选项卡中(通常是“此移动应用程序启动并运行”屏幕出现)它会将我发送到https://login.microsoftonline.com/{domain}.onmicrosoft.com/oauth2/v2.0/authorize?response_type=...
,然后将我重定向到msala{custom-redirect-uri}://auth
,这是我在我的Azure AD B2C的重定向URI原生应用。
此外,在Azure门户中我的应用服务的活动日志中,我看不到更新。当我查询数据库时,结构不会改变它应该是。
那么那里发生了什么以及为什么重定向到自定义重定向URI? Azure AD B2C与发布后端项目有什么关系?
更新:
检查打开的网页,我看到以下内容:
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd' >
<html xmlns = 'http://www.w3.org/1999/xhtml' >
<head>
<title> Logging in... </title>
<meta name = 'CACHE-CONTROL' content = 'NO-CACHE' />
<meta name = 'PRAGMA' content = 'NO-CACHE' />
<meta name = 'EXPIRES' content = '-1' />
</head>
<body >
<form id = 'auto' method = 'post' action = 'msal{Client_id}://auth'>
<div>
<input type = 'hidden' name = 'error' id = 'error' value = 'redirect_uri_mismatch' />
<input type = 'hidden' name = 'error_description' id = 'error_description' value = 'AADB2C90006: The redirect URI 'https://{domain}.azurewebsites.net/.auth/login/aad/callback' provided in the request is not registered for the client id '{Client_id}'.
Correlation ID: 9569081c-2779-41e8-8b20-095384de402f
Timestamp: 2018-02-06 18:53:38Z
'/>
<input type = 'hidden' name = 'state' id = 'state' value = 'redir=%2F' />
</div>
<div id = 'noJavascript' style = 'visibility: visible; font-family: Verdana' >
<p> Although we have detected that you have Javascript disabled, you will be able to use the site as normal. </p>
<p> As part of the authentication process this page may be displayed several times.Please use the continue button below. </p>
<input type = 'submit' value = 'Continue' />
</div>
<script type = 'text/javascript' >
< !--
document.getElementById('noJavascript').innerHTML = '';
document.getElementById('auto').submit();
//-->
</script></form></body></html>
我仍然没有看到从我的本机应用客户端(客户端ID)到我的.Net后端应用服务的连接。当然它们是相互联系的,但这不应该对他后期的发布产生任何影响
'error_description'id ='error_description'value ='AADB2C90006:请求中提供的重定向URI'https:// {domain} .azurewebsites.net / .auth / login / aad / callback'未注册客户端ID' {} CLIENT_ID”
如果我理解正确,那你就是在谈论Xamarin应用程序。通常,我们会在Azure Active Directory B2C租户中注册移动/本机应用程序,并设置自定义重定向URI /重定向URI。细节,你可以关注Register your application。
然后我们将在移动客户端中使用MSAL来检索令牌,并使用Client-managed authentication发送令牌以通过移动应用后端进行身份验证,如下所示:
var payload = new JObject();
if (authenticationResult != null && !string.IsNullOrWhiteSpace(authenticationResult.IdToken))
{
payload["access_token"] = authenticationResult.IdToken;
}
var user = await TodoItemManager.DefaultManager.CurrentClient.LoginAsync(MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory,payload);
根据您的描述,我假设您已根据移动应用程序的“设置>身份验证/授权”部分,在未向Log in with Azure Active Directory
验证请求时设置了要执行的操作。默认情况下,如果您通过浏览器访问移动设备,它将使用Server-managed authentication,此时您需要在AAD应用程序的重定向URI下设置https://{your-mobileapp-name}.azurewebsites.net/.auth/login/aad/callback
。
此外,这里有一些有用的教程,你可以参考它们:
Authenticating Users with Azure Active Directory B2C
注意:对于服务器流示例,您不需要使用MSAL,只需要直接使用特定提供程序再次登录您的移动应用程序,如下所示:
var user = await TodoItemManager.DefaultManager.CurrentClient.LoginAsync(MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory, Constants.URLScheme);
并且您需要在Azure门户上为您的移动客户端应用程序使用Add your app to the Allowed External Redirect URLs。
更新:
但是,我所做的更改并未反映在Azure DB中。但这似乎是EF Migration在应用程序启动时遇到的问题,必须首先进行配置
对于EF迁移,如果禁用自动迁移,默认情况下,数据库初始化程序将为CreateDatabaseIfNotExists
,当您的应用程序第一次访问数据库时,如果不存在,则会创建数据库。或者,您可以启用自动迁移并在Startup.MobileApp.cs文件的new DbMigrator(new Migrations.Configuration()).Update()
方法下调用ConfigureMobileApp
,此时更改将应用于应用程序启动。
由于您使用的是ClientFlow,因此请勿在AAD应用程序的重定向URI下配置https://{your-mobileapp-name}.azurewebsites.net/.auth/login/aad/callback
。在通过VS将应用程序发布到Azure端之前,您可以在LaunchSiteAfterPublish
文件下将False
设置为<your-mobile-app-name> - Web Deploy.pubxml
,因为您在注释成功完成发布后禁用自动启动网站。