Forum Discussion

oxgl's avatar
oxgl
New Contributor
10 months ago

Dynamic fields in URL

Hello!

First of all, thank you for this product — it’s almost perfect for me. I’m currently using KeePassXC while testing the trial version of 1Password.

The Linux version works perfectly, but I need to use Windows for work. As an ABAP developer, there’s one feature I’m missing: the ability to execute SAP Logon directly from 1Password. In KeePassXC, I used a URL to run the SAP application, which dynamically inserted the username, password, and other parameters from the entry fields. With just one click, I could open any system without manually entering credentials, saving me a lot of time.

I hope I’m correct in thinking that the Windows version of 1Password supports opening URLs with custom schemes. My assumption is that the system would handle these URLs by passing them to the associated handler. This would allow me to create a protocol handler for a scheme like "sapgui://", followed by the system name and credentials. The associated executable could then decode the URL and launch SAP with the necessary parameters.

However, 1Password doesn’t currently allow me to insert dynamic parameters into the URL. Would it be possible to add this functionality to the app? Specifically, I’d like the ability to include dynamic parameters or placeholders in the URL — for example, {{ username }}. This would make it much easier to pass credentials directly into applications like SAP Logon.

Thank you!

6 Replies

  • oxgl's avatar
    oxgl
    New Contributor

    Hi everyone,

    Sorry for not getting back sooner! I know some of you asked me to upload the solution, but I didn’t receive or maybe just didn’t notice any follow-up information about it. Didn’t mean to leave you hanging — thanks a lot for your patience!

    Here is my solution:

    Create a file sapgui_ph.ps1, and paste the following script into it - this will be the protocol handler for scheme "sapgui:":

    param(
        [string]$sapguiUrl
    )
    
    Add-Type -AssemblyName System.Web
    
    # Function to parse the URL parameters
    function Parse-SapGuiUrl {
        param (
            [string]$url
        )
        
        # Remove the sapgui:// part from the URL
    	$url = $url -replace '^sapgui://', ''
        $url = $url -replace '^sapgui:', ''
    
        # Split the URL into components (assuming the URL format is something like sapgui://system=<system>&user=<user>&pw=<password>)
        $params = @{}
        $url.Split('&') | ForEach-Object {
            $key, $value = $_.Split('=')
            if ($key -and $value) {
                $params[[System.Web.HttpUtility]::UrlDecode($key)] = [System.Web.HttpUtility]::UrlDecode($value)
            }
        }
        return $params
    }
    
    # Parse the URL parameters
    $params = Parse-SapGuiUrl -url $sapguiUrl
    
    # Output the parameters for verification (you can remove this line later)
    #Write-Host "Parsed Parameters: $($params | Out-String)"
    
    # Check if necessary parameters are present (like system, user, etc.)
    if ($params['system'] -and $params['client'] -and $params['user'] -and $params['pw']) {
        $system = $params['system']
    	$client = $params['client']
        $user = $params['user']
        $pw = $params['pw']
        $lang = $params['lang']
        
        if (-not $lang) {
           $lang = 'E'
        }
    
        # Example command execution (this could be a call to the SAP GUI or another command)
        Write-Host "Connecting to SAP System: $system, client: $client, with user: $user"
    
        # You can now execute your SAP GUI command or other related actions here
        # For example, launch an SAP GUI connection with the parameters (this is just an example)
        # Start-Process "sapgui.exe" -ArgumentList "/system:$system /user:$user /client:$client"
    	Start-Process -FilePath "C:\Program Files\SAP\FrontEnd\SAPGUI\sapshcut.exe" -ArgumentList "-system=`"$system`"", "-client=`"$client`"", "-user=`"$username`"", "-pw=`"$pw`"", "-language=$lang", "-maxgui"
    	
    	#Read-Host "Press enter..."
    } else {
        Write-Host "Missing required parameters in the URL."
    }


    Create a second file sapgui_ph_register.ps1 in the same directory, this will contain the script which will register the first file as a protocol handler for scheme "sapgui:":

    $protocolName = "sapgui"
    
    # Get the full path by combining the script directory with the filename
    $scriptPath = Join-Path -Path $PSScriptRoot -ChildPath "sapgui_ph.ps1"
    
    # Escape backslashes in the path (for registry compatibility)
    $escapedScriptPath = $scriptPath -replace '\\', '\\\\'
    
    # Define the registry key paths
    $protocolKey = "HKCU:\Software\Classes\$protocolName"
    $commandKey = "HKCU:\Software\Classes\$protocolName\shell\open\command"
    
    # Create the registry entries
    New-Item -Path $protocolKey -Force | Out-Null
    Set-ItemProperty -Path $protocolKey -Name "(Default)" -Value "URL:$protocolName Protocol"
    Set-ItemProperty -Path $protocolKey -Name "URL Protocol" -Value ""
    
    # Set the command to run PowerShell with the script, passing the URL as an argument
    New-Item -Path $commandKey -Force | Out-Null
    Set-ItemProperty -Path $commandKey -Name "(Default)" -Value "`"powershell.exe`" -ExecutionPolicy Bypass -File `"$escapedScriptPath`" `"%1`""
    
    Write-Host "Protocol handler for '$protocolName' registered successfully."
    

    Now just run the script sapgui_ph_register.ps1

    In 1Password add a website field:

    Unfortunately, 1Password does not allow us to reference field values (at least that was the case a few months ago), so we have to construct this URI manually. Here’s how:

    • Put the SAP System ID after system=...
    • Put the Client after client=...
    • Put the Username after user=...
    • Put your Password after pw=...
    • Don’t forget the ampersand (&) at the end

    All values must be URL-encoded before inserting them into the URI. You can use a tool like https://www.urlencoder.org/ to encode your values.

    Example:

    • System ID: CRM
    • Client: 100
    • User ID: oxgl
    • Password: pass&word! (URL-encoded as pass%26word%21)

    The resulting URI will be:

    sapgui:system=CRM&client=100&user=oxgl&pw=pass%26word%21&

    By default, this will log in using English. For non-English logins, you can add the &lang=X parameter, where X is the short language code (for example, C for Czech).

    This works with 1Password Quick Access (Ctrl + Shift + Space).

    Hope this helps!

    oxgl

  • morning OXGL,
    can you pls share me protocol and info, to launch sapgui from 1password.

    thk in advance - Paolo

  • oxgl's avatar
    oxgl
    New Contributor

    Hi 1P_Dave!

    Thank you! Auto-type is another excellent feature, but I'm not using it anymore. In the browser, I'm using the 1Password extension's autofill feature, and nowadays, the only Windows application where I need to enter credentials is SAP GUI. I use the Quick Access functionality: I press the hotkey (Ctrl-Shift-Space), type in the SAP system name, press Enter, and it opens SAP with the system already logged in.

    As I mentioned, I've created and registered my own custom protocol handler for the "sapgui:" scheme. The only downside is that I have to manually construct the URL in 1Password, including the (URL-encoded) username and password, and update it manually whenever the password changes. It would be a great feature if 1Password could automatically insert the (URL-encoded) username and password into the URL.

    One thing I've noticed is that in Quick Access, the custom protocol works, but in the client, I can only copy the URL with this custom protocol. Could you enable the ability to open custom (non-standard HTTPS) protocol schemes directly in the client application? Or at least, please do not disable this feature in Quick Access.

    Overall, I'm very satisfied with the product and have already decided to subscribe.

    Keep up the good work!

    oxgl

  • Hello oxgl! 👋

    Thank you for sharing your solution with the community! 1Password for Windows also has an auto-type feature which you mind find useful since it can fill your login credentials into other apps with you having to enter them manually:

    Let me know if there's anything else that I can help you with.

    -Dave

  • oxgl's avatar
    oxgl
    New Contributor

    Hi! The good news is that I was able to create a custom protocol handler. I entered a URL into the URL field: sapgui:system=<system_id>&client=<client>&user=<user>&pw=<password>&, and when I open it, it starts the SAP system. I registered a protocol handler for the "sapgui" protocol, which parses the string and then executes SAP. As you can see, the URL ends with "&". This is because 1P automatically adds its identifiers at the end of the URL, like "?bkgk...=VaTOiodd...". My parser splits the parameters at "&", so this value was automatically added to the password.

    It's also very important to URL encode the strings in the URL. So if your password contains special characters, you need to encode them. For example, "pass&word" should be added as ...&pw=pass%26word.

    However, there's still a limitation: we can't reference a field, so I have to manually enter the username and password into the URL.

    If you're interested in the protocol handler script (PowerShell), let me know, and I can upload it.

    • AgusMata's avatar
      AgusMata
      New Contributor

      Hi Can you please upload the protocol, and some explanation on how to use it please (Im not that technical)