[英]Using Both Active Directory Authentication and Individual User Accounts in .NET Core
[英]Azure Mobile Services .net Backend Authentication using individual user accounts
我有一個使用個人用戶帳戶的現有ASP.net Web API。
我用它來注冊/更改密碼/登錄等。登錄時,我收到一個令牌,然后使用該令牌訪問[授權]控制器。
即
[授權]公共類ValuesController:ApiController
我已經將TODO .net后端的Azure移動應用程序的Controllers,DataObjects,Startup.MobileApp和AppNameApiContext添加到了我當前的API中。
即公共類TodoController:TableController
這對於同步/插入等工作正常。但是,如果我向控制器添加[Authorize],即使我發送與其他API端點一起使用的相同令牌,也會始終返回未授權狀態。
我可以使用“ Azure移動應用程序的自定義身份驗證”找到的所有示例都使用Microsoft.Azure.Mobile.Server.Authentication。
如何使用相同的登錄名/令牌為(ValuesController:ApiController)和(TodoController:TableController)提供身份驗證
非常感謝您的期待
我正在嘗試尋找一種解決方案
app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions
{
SigningKey = signingKey,
ValidAudiences = new[] { hostName },
ValidIssuers = new[] { hostName },
TokenHandler = new MyClass (config)
});
public class MyClass : AppServiceTokenHandler
{
public override bool TryValidateLoginToken
(string token,
string signingKey,
IEnumerable<string> validAudiences,
IEnumerable<string> validIssuers,
out ClaimsPrincipal claimsPrincipal)
{
if (CheckIfUserIsAuth(token))
{
return true;
}
// Or something like
// if(token== CurrentUserToker)
// { return true};
}
}
但是,無論我返回true還是false,我仍然會收到未經授權的信息。
不幸的是,您是從錯誤的角度出發。 您需要從Azure移動應用程序開始。 它具有必要的邏輯,可以使用EasyAuth從移動設備進行身份驗證。 我建議從本教程開始-它具有您選擇的前端和后端。 然后可以根據需要擴展。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.