Sys.Services.AuthenticationService 클래스
업데이트: 2007년 11월
인증 서비스에 클라이언트 프록시 클래스를 제공합니다.
네임스페이스:Sys.Services
상속: 없음
멤버
이름 |
설명 |
---|---|
Sys.Services.AuthenticationService 클래스의 새 인스턴스를 초기화합니다. |
|
기본 인증 서비스의 경로를 지정합니다. |
|
사용자의 자격 증명을 인증합니다. |
|
현재 인증된 사용자를 로그아웃합니다. |
|
기본 실패 콜백 함수의 이름을 가져오거나 설정합니다. |
|
Sys.Services AuthenticationService defaultLoginCompletedCallback 속성 |
로그인 완료 기본 콜백 함수의 이름을 가져오거나 설정합니다. |
Sys.Services AuthenticationService defaultLogoutCompletedCallback 속성 |
로그아웃 완료 기본 콜백 함수의 이름을 가져오거나 설정합니다. |
Sys.Services AuthenticationService defaultSucceededCallback 속성 |
서비스에 대한 기본 성공 콜백 함수를 가져오거나 설정합니다. |
서비스에 대한 기본 사용자 컨텍스트를 가져오거나 설정합니다. |
|
현재 사용자의 인증 상태를 가져옵니다. |
|
인증 서비스 경로를 가져오거나 설정합니다. |
|
인증 서비스 제한 시간을 가져오거나 설정합니다. |
설명
AuthenticationService 클래스를 사용하면 스크립트를 통해 사용자 인증 서비스에 액세스할 수 있습니다. 이 클래스는 다른 모든 웹 서비스 메서드를 호출하는 데 사용되는 것과 같은 인프라를 통해 인증 서비스의 메서드를 호출합니다.
참고
기본 제공되는 인증 서비스는 서버에서 미리 정의된 위치에 있습니다.
AuthenticationService 클래스는 전역 액세스 지점을 제공하는 하나의 인스턴스만 포함된 singleton 개체입니다. 이 클래스는 응용 프로그램에서 항상 사용할 수 있으므로 인스턴스화할 필요가 없습니다.
예제
설명
다음 예제에서는 AuthenticationService 클래스를 사용하여 사용자가 인증되었는지 여부를 확인하는 방법을 보여 줍니다. 자세한 내용은 ASP.NET AJAX에서 폼 인증 사용을 참조하십시오.
코드
// Define global variables.
var usernameEntry;
var passwordEntry;
var username;
var password;
var textLoggedIn;
var textNotLoggedIn;
var buttonLogin;
var buttonLogout;
function pageLoad()
{
usernameEntry = $get("NameId");
passwordEntry = $get("PwdId");
username = $get("username");
password = $get("password");
textLoggedIn = $get("loggedin");
textNotLoggedIn = $get("notloggedin");
buttonLogin = $get("ButtonLogin");
buttonLogout = $get("ButtonLogout");
}
// This function sets and gets the default
// login completed callback function.
function SetDefaultLoginCompletedCallBack()
{
// Set the default callback function.
Sys.Services.AuthenticationService.set_defaultLoginCompletedCallback(OnLoginCompleted);
// Get the default callback function.
var callBack =
Sys.Services.AuthenticationService.get_defaultLoginCompletedCallback();
}
// This function sets and gets the default
// logout completed callback function.
function SetDefaultLogoutCompletedCallBack()
{
// Set the default callback function.
Sys.Services.AuthenticationService.set_defaultLogoutCompletedCallback(OnLogoutCompleted);
// Get the default callback function.
var callBack =
Sys.Services.AuthenticationService.get_defaultLogoutCompletedCallback();
}
// This function sets and gets the default
// failed callback function.
function SetDefaultFailedCallBack()
{
// Set the default callback function.
Sys.Services.AuthenticationService.set_defaultFailedCallback(OnFailed);
// Get the default callback function.
var callBack =
Sys.Services.AuthenticationService.get_defaultFailedCallback();
}
// This function calls the login method of the
// authentication service to verify
// the credentials entered by the user.
// If the credentials are authenticated, the
// authentication service issues a forms
// authentication cookie.
function OnClickLogin()
{
// Set the default callback functions.
SetDefaultLoginCompletedCallBack();
SetDefaultLogoutCompletedCallBack();
SetDefaultFailedCallBack();
// Call the authetication service to authenticate
// the credentials entered by the user.
Sys.Services.AuthenticationService.login(username.value,
password.value, false,null,null,null,null,"User Context");
}
// This function calls the logout method of the
// authentication service to clear the forms
// authentication cookie.
function OnClickLogout()
{
// Clear the forms authentication cookie.
Sys.Services.AuthenticationService.logout(null,
null, null, null);
}
// This is the callback function called
// if the authentication fails.
function OnFailed(error,
userContext, methodName)
{
// Display feedback message.
DisplayInformation("error:message = " +
error.get_message());
DisplayInformation("error:timedOut = " +
error.get_timedOut());
DisplayInformation("error:statusCode = " +
error.get_statusCode());
}
// The callback function called
// if the authentication completed successfully.
function OnLoginCompleted(validCredentials,
userContext, methodName)
{
// GetPageElements();
// Clear the user password.
password.value = "";
// On success there will be a forms
// authentication cookie in the browser.
if (validCredentials == true)
{
// Clear the user name.
username.value = "";
// Hide login fields.
buttonLogin.style.visibility = "hidden";
usernameEntry.style.visibility = "hidden";
passwordEntry.style.visibility = "hidden";
textNotLoggedIn.style.visibility = "hidden";
// Display logout fields.
buttonLogout.style.visibility = "visible";
textLoggedIn.style.visibility = "visible";
// Clear the feedback area.
DisplayInformation("");
}
else
{
textLoggedIn.style.visibility = "hidden";
textNotLoggedIn.style.visibility = "visible";
DisplayInformation(
"Login Credentials Invalid. Could not login");
}
}
// This is the callback function called
// if the user logged out successfully.
function OnLogoutCompleted(result)
{
// Display login fields.
usernameEntry.style.visibility = "visible";
passwordEntry.style.visibility = "visible";
textNotLoggedIn.style.visibility = "visible";
buttonLogin.style.visibility = "visible";
// Hide logout fields.
buttonLogout.style.visibility = "hidden";
textLoggedIn.style.visibility = "hidden";
}
// This function displays feedback
// information for the user.
function DisplayInformation(text)
{
// var feedBack =
// document.getElementById("FeedBackID").innerHTML;
document.getElementById("FeedBackID").innerHTML =
"<br/>" + text;
// Display authentication service information.
var userLoggedIn =
Sys.Services.AuthenticationService.get_isLoggedIn();
var authServiceTimeout =
Sys.Services.AuthenticationService.get_timeout();
var userLoggedInfo =
"<br/> User logged in: " + userLoggedIn;
var timeOutInfo =
"<br/> Authentication service timeout: " + authServiceTimeout;
document.getElementById("FeedBackID").innerHTML =
userLoggedInfo + timeOutInfo;
}
// Notify ScriptManager that this is the end of the script.
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();