Quantcast
Channel: Scripting Languages
Viewing all articles
Browse latest Browse all 68

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

$
0
0

Hello community,

 

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-----------------------------------------------------------------

 

  '-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

 

      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.

 

Enjoy it.

 

Cheers

Stefan


Viewing all articles
Browse latest Browse all 68

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>