Skip to Content
Technical Articles

How To Use Single Sign On (SSO) With COM Connector (CCo)

Here an example how to us Single Sign On (SSO) with CCo. In the function RfcGetPartnerSSOTicket – the name is equivalent to the function in the NWRFC library – I use the ABAP function module SUSR_CHECK_LOGON_DATA to get the ticket. With this ticket is it now easy possible to log on to other systems. In my example I log on to another system and to the same system again.

'-Begin-----------------------------------------------------------------
'-
'- TAC STRUSTSSO2
'-
'-----------------------------------------------------------------------


  '-Directives----------------------------------------------------------
    Option Explicit


  '-Constants-----------------------------------------------------------
    Const RFC_OK = 0


  '-RfcGetPartnerSSOTicket----------------------------------------------
    Function RfcGetPartnerSSOTicket(SAP, hRFC, UserID, PassWd)

      '-Variables-------------------------------------------------------
        Dim rc, hFuncDesc, hFunc, Ticket

      hFuncDesc = SAP.RfcGetFunctionDesc(hRFC, "SUSR_CHECK_LOGON_DATA")
      If hFuncDesc = 0 Then
        rc = SAP.RfcCloseConnection(hRFC)
        Exit Function
      End If

      hFunc = SAP.RfcCreateFunction(hFuncDesc)
      If hFunc = 0 Then
        rc = SAP.RfcCloseConnection(hRFC)
        Exit Function
      End If

      rc = SAP.RfcSetChars(hFunc, "AUTH_METHOD", "P")
      rc = SAP.RfcSetChars(hFunc, "USERID", UserID)
      rc = SAP.RfcSetChars(hFunc, "PASSWORD", PassWd)

      Ticket = Space(2048)
      If SAP.RfcInvoke(hRFC, hFunc) = RFC_OK Then
        rc = SAP.RfcGetChars(hFunc, "TICKET", Ticket, 2048)
      End If

      rc = SAP.RfcDestroyFunction(hFunc)

      RfcGetPartnerSSOTicket = Trim(Ticket)

    End Function


  '-Main----------------------------------------------------------------
    Sub Main()

      '-Variables-------------------------------------------------------
        Dim SAP, UserID, PassWd, hRFC, rc, Ticket

      Set SAP = CreateObject("COMNWRFC")
      If Not IsObject(SAP) Then
        Exit Sub
      End If

      SAP.GetUserPasswordDialog " for NSP", UserID, PassWd

      hRFC = SAP.RfcOpenConnection("ASHOST=NSP, SYSNR=00, CLIENT=001, " & _
        "USER=" & UserID & ", PASSWD=" & PassWd)
      If hRFC = 0 Then
        Set SAP = Nothing
        Exit Sub
      End If

      'rc = SAP.RfcGetPartnerSSOTicket(hRFC, Ticket, 2048)
      'Delivers RFC_ILLEGAL_STATE error

      Ticket = RfcGetPartnerSSOTicket(SAP, hRFC, UserID, PassWd)

      rc = SAP.RfcCloseConnection(hRFC)

      SAP.UsePwdRequest = 0

      hRFC = SAP.RfcOpenConnection("ASHOST=NST, SYSNR=01, CLIENT=001, " & _
        "MYSAPSSO2=" & Ticket)
      If hRFC Then
        MsgBox "Connected to NST via SSO"
        rc = SAP.RfcCloseConnection(hRFC)
      End If

      hRFC = SAP.RfcOpenConnection("ASHOST=NSP, SYSNR=00, CLIENT=001, " & _
        "MYSAPSSO2=" & Ticket)
      If hRFC Then
        MsgBox "Connected to NSP via SSO"
        rc = SAP.RfcCloseConnection(hRFC)
      End If

      Set SAP = Nothing

    End Sub


  '-Main----------------------------------------------------------------
    Main


'-End-------------------------------------------------------------------

The method GetUserPasswordDialog opens a dialog to get the user name and the password. On this way it is now very easy in VBScript to get those kind of data.

2 Comments
You must be Logged on to comment or reply to a post.
  • Hi Stefan ,

    Thanks for the information .
    From where do we know the password needed   ?

    hRFC = SAP.RfcOpenConnection("ASHOST=NSP, SYSNR=00, CLIENT=001, " & _
            "USER=" & UserID & ", PASSWD=" & PassWd)

    ( since user dose not knows the passwords in single sign on )

     

    Regards,

    Ziv

    • Hello Ziv,

      a user has to log in somewhere once, with its name and password, and there you get the SSO ticket. In my example I use two different SAP systems. The first to log in and to get the SSO ticket for the second. And the second system to connect with the ticket.

      Best regards
      Stefan