AIMCC Technote 12

Seamless authentication onto the AIM Startpage and the AIM Expressions Chooser


Overview

This technote demonstrates how your custom client can authenticate users onto the AIM Startpage and the AIM Expressions Chooser web sites.

Using the Open AIM SDK you can seamlessly sign on to these web sites via the following API: IAccSession::RequestService. The result will be returned via DAccEvents::OnRequestServiceResult.

In the following code samples, we will demonstrate how to implement this code in the following languages, C++, C#, VB.NET, and Java. We also have sample clients included showing this code in the Open AIM SDK. You can find the clients in the "samples" folder.

The URLs for accessing the AIM Expressions Chooser and AIM Startpage for custom clients are as follows. When constructing the URL, the last parameter that must be passed in is the developer key that is used to authenticate the client on the network.

C++ Example:

static _ATL_FUNC_INFO orsrInfo =
    { CC_STDCALL, VT_EMPTY, 6, { VT_DISPATCH, VT_I4, VT_I4, VT_BSTR, VT_I4, VT_VARIANT } };
    
class CSessionManager : public CComObjectRoot,    
    public IDispEventImpl<1, CSampleApp, &__uuidof(DAccEvents), &LIBID_AccCoreLib, 1>
{

private:
CComPtr<IAccSession> m_spiSession;
CAtlList<int>        m_requests;
	
public:

// DAccEvents Methods    
BEGIN_SINK_MAP(CSessionManager) 
    SINK_ENTRY_INFO(1, __uuidof(DAccEvents), 
        ACCDISPID_ONREQUESTSERVICERESULT, OnRequestServiceResult, &orsrInfo)
END_SINK_MAP() 

HRESULT Init(const char* userName, const char* password)
{        
    // create aimcc main object, hook up for events, set id, and signon
    HRESULT hr;
    if (SUCCEEDED(hr = AccCreateSession(IID_IAccSession, (void**)&m_spiSession)) &&
        SUCCEEDED(hr = DispEventAdvise(m_spiSession)) &&
        SUCCEEDED(hr = m_sp->put_Identity(CComBSTR(userName))))
    {
        // more code goes here
    }
    return hr
}
HRESULT CSessionManager::RequestService()
{
    // request authenetication to load the 
    // AIM Startpage web page, replace DEVKEY with
    // the developer key used when signing into the AIM network
    AccTransId transId;
    m_spiSession->RequestService(CComBSTR("http://api.oscar.aol.com/aim/getStartPage?f=html&language=en-us&k=DEVKEY"), CComVariant(), &transId);
    if (SUCCEEDED(hr))
        m_requests.AddTail(id);
    return hr;
}

HRESULT CSessionManager::OnRequestServiceResult(IAccSession* piSession, AccTransId transId, 
                                            AccResult hr, xp_kstr host, xp_int port, xp_kvariant cookie)
{
    // ignore requests that we did not make... important!
    POSITION pos = m_requests.Find(transId);
    if (!pos)
        return S_FALSE;
        
    // We know this is our request.

    // Remove this transId from the list.
    m_requests.RemoveAt(pos);

    // Load the URL in a new default browserwindow. 'host' argument has URL.
    if (host && host[0])
        ShellExecute(NULL, NULL, host, NULL, NULL, SW_SHOW);

    return S_OK;
}

};

C# Example:

private AccSession s;	
private int[] transIdMap;
private void Run(string username, string password)
{
    try 
    {
        // create control to allow invokes
        CreateControl();	
				
        // create and init session
        object o;
        AccCreateSession(typeof(IAccSession).GUID, out o);				
        s = (AccSession)o;

        // we need to set up a listener for getting logged into the expressions web page
        s.OnRequestServiceResult += new DAccEvents_OnRequestServiceResultEventHandler(s_OnRequestServiceResult);
    }
    catch (COMException e)
    {
        Console.WriteLine(e.Message);
    }
}

private void RequestService()
{
    try
    {
        // request a token for the AIM Startpage web page, replace DEVKEY with
        // the developer key used when signing into the AIM network
        // save the transId so we handle the result we requested
        // in the callback and not any other request made by a plugin
        int transId = s.RequestService("http://api.oscar.aol.com/aim/getStartPage?f=html&language=en-us&k=DEVKEY", (object)"");
        int i = transIdMap.Length;
        transIdMap[i] = transId;
    }
    catch (System.Runtime.InteropServices.COMException ex)
    {
        Console.WriteLine("There was an error getting the expressions page {0}.", ex.ErrorCode);	
    } 
}

private void s_OnRequestServiceResult(AccSession session, int transId, AccResult hr, string host, int port, object cookie)
{
    // check the transId to make sure we made the request
    foreach (int i in transIdMap)
    {
        if (transId == i)
        {
            // we know we have our request, now load the URL in a new default browser
            // window using the host param.
            System.Diagnostics.Process.Start(host);
        }
    }
}

VB.NET Example:

Private s As AccSession
Private transIdMap() As Integer

Public Sub Run(ByVal username As String, ByVal password As String)
    Try
        ' create control to allow invokes
        CreateControl()

        ' create and init session
        Dim o As Object
        AccCreateSession(GetType(IAccSession).GUID, o)
        s = CType(o, AccSession)

        ' we need to set up a listener for getting logged into the expressions web page
        AddHandler s.OnRequestServiceResult, AddressOf s_OnRequestServiceResult                    
       ...
   Catch e As COMException
       Console.WriteLine(e.Message)
   End Try
End Sub                    

Public Sub RequestService()
    Try
        ' request a token for the AIM Startpage web page replace DEVKEY with
        ' the developer key used when signing into the AIM network
        ' save the transId so we handle the result we requested
        ' in the callback and not any other request made by a plugin
        Dim transId As Integer = s.RequestService("http://api.oscar.aol.com/aim/getStartPage?f=html&language=en-us&k=DEVKEY", "")
        Dim i As Integer = transIdMap.Length
        transIdMap(i) = transId
        Catch ex As System.Runtime.InteropServices.COMException
        Console.WriteLine("There was an error getting the expressions page {0}.", ex.ErrorCode)
    End Try
End Sub

Private Sub s_OnRequestServiceResult(ByVal session As AccSession, ByVal transId As Integer, ByVal hr As AccResult, ByVal host As String, ByVal port As Integer, ByVal cookie As Object)
    ' check the transId to make sure we made the request
    Dim i As Integer
    For Each i In transIdMap
        If transId = i Then
            ' we know we have our request, now load the URL in a new default browser
            ' window using the host param.
            System.Diagnostics.Process.Start(host)
        End If
    Next
End Sub           

Java Example:

public AccJSample(String username, String password, String key) throws AccException
{
    // Create main session object
    session = new AccSession();

    // Add event listener
    session.setEventListener(this);

    // set key
    AccClientInfo info = session.getClientInfo();
    info.setDescription(key);

    // set screen name
    session.setIdentity(username);

    session.signOn(password);

    msgPump();
}

priavte void RequestService
{
    // request sign on to the AIM Startpage, replace DEVKEY
    // with the developer key used in the function AccJSample
    session.requestService("http://api.oscar.aol.com/aim/getStartPage?f=html&language=en-us&k=DEVKEY", "")'
}

private void msgPump()
{
    //msg pump
    while( running ) 
    {
        try {
            AccSession.pump(50);
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        try {
            Thread.sleep(50);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

public void OnRequestServiceResult(AccSession arg0, int arg1, AccResult arg2, String arg3, int arg4, byte[] arg5) {

}


rev. 2008/03/03