0
私は、ユーザIDとパスワードに基づいてGETコールとしてアクティブディレクトリから詳細をフェッチするコードを書いています。私はユーザーIDとパスワードを - http://localhost:1234/api/User/IsAuthorized/UserID=1234;password=qwerty のようなURLに渡していますが、これは危険な方法です。誰が私の体にこれらの値を渡すためのソリューションを提供し、POSTコールとしてそれを使用する代わりに 私のコードはWeb APIのC#でget呼び出しのためのURLにIDとパスワードを渡すのを防ぐには?
[Route("IsAuthorized/UserID={userName};password={password}")]
[AllowAnonymous]
public IHttpActionResult GetIsAuthorized(string userName,string password)
{
HttpResponseMessage response = null;
string errorMessage = null;
bool hasError = false;
bool isValid;
UserDetails detail = null;
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, "ABC"))
{
isValid = pc.ValidateCredentials(userName, password);
string token = null;
if (isValid)
{
detail = IsAuthenticated("abc", userName, password, out errorMessage, out hasError);
}
if (hasError)
{
detail = new UserDetails(isValid, userName, null, null, null, errorMessage, null);
}
else
{
if (detail != null)
{
token = CreateToken(userName);
detail = new UserDetails(isValid, userName, detail.AssociateName, detail.Mobile, detail.Email, null, token);
}
else
detail = new UserDetails(isValid, userName, null, null, null, "unknown username or bad password", null);
}
return Ok(detail);
}
}
なぜPOSTリクエストでパスワードを渡すのが安全だと思いますか?まだ平易なテキストです... –
@RB。 URLの場合のように公開されません – Prabhjot
ええと - これは本当に小さな部分ですが、結局のところ、URLを見ることができるユーザーは最初にそれを入力したユーザーです。あなたはなぜパスワードを渡さなければならないのですか?結局のところ、Webサービスは "UserIsAuthorized"と呼ばれています。ユーザーが承認されているかどうかを調べるには、ユーザーIDを渡す必要があります。 –