Table of Content Zone | ||
---|---|---|
| ||
OverviewInteractive login is to be used when the user is present to login (for example, 3rd Party Desktop Applications) and will manage any additional information required at login depending upon a customer's account (such as 2 Factor Authentication codes or National Identifiers). This is achieved by embedding the Betfair IdentitySSO login page in your application and then obtaining a successful session token upon login. The |
...
Keep Alive operation should be called |
...
within session expiry time if the user is still actively using your application. |
...
You should be able to detect the presence of a session token in the requests upon successful login for use by your application.
Interface
Login
URL definition
International users:
https: //identitysso.betfair.com/view/login?product=<theProductDescriptor>&url=<theRedirectUrl> |
Spanish jurisdiction users:
https: //identitysso.betfair.es/view/login?product=<theProductDescriptor>&url=<theRedirectUrl> |
Italian jurisdiction users:
https: //identitysso.betfair.it/view/login?product=<theProductDescriptor>&url=<theRedirectUrl> |
...
Obtaining the sessionToken from the POST dataOnce a login has been successfully made, the Javascript in the page will POST the session token (ssoid) to the URL provided as a redirect URL. For a desktop application, this is not required to be a real page as the desktop application can intercept the POST request as it happens via the embedded browser container. A Windows based application can embed a web browser into the application and use the BeforeNavigate2 event to catch the post data sent to the redirect URL and there are platform specific alternatives. The POST request body will contain two URL encoded parameters (which you will need to URL Decode):
The Interactive Login is the same login flow used by the Betfair website and therefore, any message's will be returned directly by Betfair & handled in the same way.
|
...
Keep Alive
URL definition
International jurisdictions:
URL Definition (Global)
|
...
...
URL Definition - Other JurisdictionsPlease use the below if your country of residence is in one of the list jurisdictions.
|
...
|
...
Italian jurisdiction:
|
...
...
NONE
Logout
URL definition
International jurisdictions:
|
...
|
...
...
|
...
|
...
Italian jurisdiction:
|
...
|
...
Parameters
|
...
|
...
|
...
|
...
|
...
|
Sample Code
A sample client, written in C#, is available to demonstrate this process on Github. This is a C# project created under Visual Studio 2010, written against .Net 4, and is a Winforms Application.
The key steps demonstrated by this client are:
- Embed identitysso.betfair.com into your application
- Handle the login method and retrieval of a session token from the cookies
- Handle the keep alive method
- Handle the logout method
How it works
Upon start-up, the URL of the API login page is assigned to the web browser control:
Code Block |
---|
//Give embedded web browser Betfair api login page URL
System.Uri u = new Uri(LogonURL);
|
When the web browser control receives data an event is triggered and the following function called:
Code Block |
---|
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
//On embeded web browser response get cookie
string cookie = this.webBrowser1.Document.Cookie;
if (cookie != null)
this.ParseCookie(cookie);
//If successfull login start KeepAlive
if (!m_LoggedOut && !m_KeepAliveTimer.Enabled)
{
webBrowser1.Visible = false;
SetMessage("Logon successfull\r\n SSOID=" + m_SSOID);
this.StartKeepAlive();
}
}
|
Upon successful login the cookie is parsed for the SSOID. The webrowser control made invisible and the SSOID displayed in a TextBox. The keep-alive timer is started
Code Block |
---|
private void StartKeepAlive()
{
m_KeepAliveTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnKeepAliveTimer);
// Set the Interval to 15 mins.
m_KeepAliveTimer.Interval = 1000 * 60 * 15;
m_KeepAliveTimer.Enabled = true;
}
|
Above the StartKeepAlive function simply starts a 15 minute timer which invokes function OnKeepAliveTimer.
OnKeepAliveTimer sends a Keep Alive message.
A message to this effect is then displayed.
Upon hitting the Logout button the following event handler is invoked:
Code Block |
---|
private void btnLogout_Click(object sender, EventArgs e)
{
m_KeepAliveTimer.Enabled = false;
m_KeepAliveTimer.Close();
m_LoggedOut = true;
System.Uri u = new Uri(LogoutURL);
this.webBrowser1.Url = u;
this.webBrowser1.Navigate(u);
SetMessage("Logged out");
}
|
The keep alive timer is closed. The logout url is sent and a Logged out message is displayed.
|