Friday, September 21, 2018

SSO > C# .Net Sample code for invoking ssoLogin which redirects the user to the Netsuite Page, logged in.


A working sample of C#.Net that invokes ssoLogin WS method. You can use this after you've generated the SSO Token string. This also requires the Netsuite Account ID and the Partner ID (PID)

1. Create a C#.Net Project that contains text boxes that will accept the token string, Netsuite Account Id and Partner ID.

2. Create this method on click of "Log In" Button.

private void btnLogIn_Click(object sender, EventArgs e){

try{

SsoPassport sso = new SsoPassport();

sso.authenticationToken = txtAuthKey.Text.ToString();

sso.partnerId = txtPartnerID.Text.ToString();

sso.partnerAccount = txtPartnerAccount.Text.ToString();

SessionResponse resp = _service.ssoLogin(sso);

string url = "https://system.netsuite.com/pages/partners/singlesignon.jsp?";

url += "a=" + txtAuthKey.Text.ToString();

url += "&pid=" + txtPartnerID.Text.ToString();

url += "&pacct=" + txtPartnerAccount.Text.ToString();

if (resp.status.isSuccess)

{

lblResponse.Text = "Login Successful";

System.Diagnostics.Process.Start(url);

}

else

lblResponse.Text = "Login Failed";

}

catch (Exception ex)

{

lblResponse.Text = ex.Message;

}

}

 

 

3. So, when you typed in the required objects (Token String, Netsuite Account ID, Partner ID), if the login is successful, you'll be redirected to your Netsuite account, Otherwise, you'll be notified that the login failed.

 

No comments:

Post a Comment