3 de abril de 2011

Criar um Ticket de autenticação SSO (Live@edu) Parte II

Este código utiliza partes e namespaces do SDK citado neste post:

http://msedulive.blogspot.com/2011/04/onde-posso-encontrar-o-liveedu-sdk-em.html

 

/// <summary>
/// Admin Center Api Binding.
/// </summary>
Microsoft.AdminCenterAPI.ManageDomain2 srvc;

public AdminCenter(string emailId, string password)
{
this.emailId = emailId;
this.password = password;
CreateAuthTicket();
}

/// <summary>
/// private method used to create the authenticated management session
/// </summary>
/// <returns>
/// The login ticket obtained for the session (not used outside of this function)
/// </returns>
private string CreateAuthTicket()
{
srvc = new Microsoft.AdminCenterAPI.ManageDomain2();


//Get the URL for obtaining the ticket
string loginUrl = srvc.GetLoginUrl(this.emailId);

//Get the template for the ticket request and replace
//the username and password placeholders
string loginTemplate = srvc.GetLoginDataTemplate().Replace("%NAME%", this.emailId).Replace("%PASSWORD%", this.password);

//Post the Login ticket to the provided URL and get the
///authorization ticket
string loginTicket = PostWebData(loginUrl, loginTemplate);

//Verify that no errors occured
if (srvc.VerifyAuthData(loginTicket))
{
//Create an instance of the
//ManageDomain2Authorization class for storing the
//ticket and ticket type
Microsoft.AdminCenterAPI.ManageDomain2Authorization srvcAuth = new Microsoft.AdminCenterAPI.ManageDomain2Authorization();

//Set the ticket type
srvcAuth.authorizationType = Microsoft.AdminCenterAPI.ManageDomain2AuthorizationType.PassportTicket;

//Set the ticket data
srvcAuth.authorizationData = loginTicket;

//Store the ManageDomain2Authorization instance
//in the Web reference
srvc.ManageDomain2AuthorizationValue = srvcAuth;
return loginTicket;
}
else
{
throw new Exception("An error occurred" + " while attempting to create an authorization ticket");
}
}



Sem comentários:

Enviar um comentário

Like