LDAP.Bind
---------

Authenticates a client to the LDAP server.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [LDAP](component_LDAP.md) | [6.0](newinversion60.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ❌ No |

MBS( "LDAP.Bind"; LDAPRef; DN; Cred; AuthMethod { ; Domain } ) 

**MBS**( **"LDAP.Bind"** /\* Authenticates a client to the LDAP server. \*/  
**$LDAPRef**; /\* The reference number for the LDAP connection. e.g. $ldap \*/   
**$DN**; /\* Test that contains the distinguished name of the entry used to bind. This can be a DN, a UPN, a WinNT style user name, or other name that the directory server will accept as an identifier. \*/   
**$Cred**; /\* The credentials with which to authenticate. Arbitrary credentials can be passed using this parameter. The format and content of the credentials depends on the setting of the method parameter. \*/   
**$AuthMethod**; /\* The authentication method to use.  
Can be simple, SASL or Negotiate.  
On macOS, also none, KRBv4, KRBv41 and KRBv42 are accepted.  
On Windows, also Sicily, MSN, NTLM, DPA, SSPI, Digest and External are accepted. e.g. "simple" \*/   
**$Domain**) /\* Optional; Domain for Windows. \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| LDAPRef | The reference number for the LDAP connection. | $ldap |  |
| DN | Test that contains the distinguished name of the entry used to bind. This can be a DN, a UPN, a WinNT style user name, or other name that the directory server will accept as an identifier. |  |  |
| Cred | The credentials with which to authenticate. Arbitrary credentials can be passed using this parameter. The format and content of the credentials depends on the setting of the method parameter. |  |  |
| AuthMethod | The authentication method to use.   Can be simple, SASL or Negotiate.   On macOS, also none, KRBv4, KRBv41 and KRBv42 are accepted.   On Windows, also Sicily, MSN, NTLM, DPA, SSPI, Digest and External are accepted. | "simple" |  |
| Domain | Domain for Windows. |  | Optional |

### Result

Returns OK or error.

### Description

Authenticates a client to the LDAP server.  
See also [SystemInfo.ADSystemInfo](SystemInfoADSystemInfo.md) function to query details about logged in computer user.  
### Examples

Authenticate connection:

 Set Variable \[$r ; Value:MBS ("LDAP.Bind"; $ldap ; $UserName ; $Password ; $AuthMethod )\]  
Example script to connect and bind:

 # ========================================   
\# Purpose:   
\# Common routine to bind to the LDAP server   
\# Returns:   
\# $error = Error code if unsuccessful   
\# $error = 0 for success   
\# $resultText = Text summary of the success or error   
\# Parameters:   
\# $serverName   
\# $serverDomain   
\# Called from:   
\# (script) All "worker" LDAP scripts   
\# Author:   
\# John Munro (HJM) from Deutsche Schule Tokyo Yokohama   
\# Notes:   
\# none   
\# History:   
\# 2021-05-20 HJM - created   
\# ========================================   
\#   
Set Variable \[ $! ; Value: #Assign ( Get ( ScriptParameter ) ) \]   
Set Variable \[ $bindUsername ; Value: "filemakerbind" \]   
Set Variable \[ $bindPassword ; Value: "xxxxxxxxx" \]   
\#   
Set Error Capture \[ On \]  
\#   
\# If debugging these parameters will be empty so fill with test data   
If \[ $serverName = "" \]   
 Set Variable \[ $serverName ; Value: "sys-xxx" \]   
End If  
If \[ $serverDomain = "" \]   
 Set Variable \[ $serverDomain ; Value: "xxx.com" \]   
End If  
\#   
Set Variable \[ $serverFQDN ; Value: $serverName &amp; "." &amp; $serverDomain \]   
\#   
\# Connect   
Set Variable \[ $ssl ; Value: 1 \]   
Set Variable \[ $port ; Value: 636 \]   
Set Variable \[ $result ; Value: MBS ( "[LDAP.Connect](LDAPConnect.md)" ; $serverFQDN ; $ssl ; $port ) \]   
If \[ MBS ( "IsError" ) \]   
 // Show Custom Dialog \[ "LDAP Error" ; "Failed to connect to Domain Controller." &amp; ¶ &amp; $result \]   
 Exit Script \[ Text Result: # ( "error" ; $result ) &amp; # ( "resultText" ; "LDAP error. Failed to connect to Domain Controller." &amp; ¶ &amp; $result ) \]   
End If  
\#   
\# Login   
Set Variable \[ $ldap ; Value: $result \]   
Set Variable \[ $result ; Value: MBS ("LDAP.Bind"; $ldap ; $bindUsername &amp; "@" &amp; $serverDomain ; $bindPassword ; "simple") \]   
If \[ MBS ( "IsError" ) \]   
 // Show Custom Dialog \[ "LDAP Error" ; "Failed to authenticate." &amp; ¶ &amp; $result \]   
 Exit Script \[ Text Result: # ( "error" ; $result ) &amp; # ( "resultText" ; "LDAP error. Failed to authenticate." &amp; ¶ &amp; $result ) \]   
End If  
\#   
\# Return error free result   
Exit Script \[ Text Result: # ( "error" ; 0 ) &amp; # ( "resultText" ; "Bind successful" ) &amp; # ( "ldap" ; $ldap ) \]  
### See also

- [IsError](IsError.md)
- [LDAP.AddJSON](LDAPAddJSON.md)
- [LDAP.Connect](LDAPConnect.md)
- [LDAP.JSON](LDAPJSON.md)
- [SystemInfo.ADSystemInfo](SystemInfoADSystemInfo.md)

### Release notes

- **Version 15.5**
    - Fixed [LDAP.Bind](https://www.mbsplugins.eu/LDAPBind.shtml) to remove ldaps:// or ldap:// prefixes on Windows.

### Example Databases

- [Network/LDAP Query](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Network/LDAP%20Query.shtml#1ScriptAnchor_)

### Blog Entries

- [MBS FileMaker Plugin, version 15.5pr1](https://www.mbsplugins.de/archive/2025-10-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [LDAP with JSON](https://www.mbsplugins.de/archive/2017-12-11/LDAP_with_JSON/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 6.1pr2](https://www.mbsplugins.de/archive/2016-02-10/MBS_FileMaker_Plugin_version_6/monkeybreadsoftware_blog_filemaker)
- [LDAP in FileMaker](https://www.mbsplugins.de/archive/2015-12-16/LDAP_in_FileMaker/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 15th December 2015 , last changed 27th July 2021

  
[LDAP.AddRecord](LDAPAddRecord.md) - [LDAP.Connect](LDAPConnect.md)

[HTML Version](LDAPBind.shtml)