Main Content

setCustomLoginProvider

Register custom authentication callback function to OSLC client

Since R2021b

    Description

    setCustomLoginProvider(myClient,authenticationFunction) registers a custom authentication callback function, authenticationFunction, for the OSLC client object myClient. You can use this function to authenticate an OSLC client object on networks that require advanced authentication that the default authentication process does not support.

    Note

    The custom authentication callback function should take this form:

    function [success,cookies] = myCustomLoginProvider(server,options)
    % Provide your implementation here
    end
    The custom authentication function should return two arguments: success status and the authenticated cookies received from the server as a matlab.net.http.field.CookieField object.

    example

    Examples

    collapse all

    This example shows how to authenticate an OSLC client by using a custom authentication function and custom HTTP options.

    Create the OSLC client.

    myClient = oslc.Client;

    Set the server URL, service root, and catalog path for your service provider.

    setServer(myClient,'http://example.com');
    setServiceRoot(myClient,'rm');
    setCatalogPath(myClient,'oslc/services/catalog');

    Create and enter the user credentials by using the matlab.net.http.Credentials class with a basic matlab.net.http.AuthenticationScheme object.

    creds = matlab.net.http.Credentials('Username','jdoe','Password', ...
    'Password1234','scheme',matlab.net.http.AuthenticationScheme.Basic);
    

    Create custom HTTP options by using the matlab.net.http.HTTPOptions class constructor. Set the Credentials property and certificate information for the custom HTTP options.

    opts = matlab.net.http.HTTPOptions('Credentials',creds, ...
        'VerifyServerName', false, 'CertificateFilename', '')
    opts = 
    
      HTTPOptions with properties:
    
               MaxRedirects: 20
             ConnectTimeout: 10
                   UseProxy: 1
                   ProxyURI: []
               Authenticate: 1
                Credentials: [1×1 matlab.net.http.Credentials]
         UseProgressMonitor: 0
                SavePayload: 0
            ConvertResponse: 1
             DecodeResponse: 1
         ProgressMonitorFcn: []
        CertificateFilename: ""
           VerifyServerName: 0
                DataTimeout: Inf
            ResponseTimeout: Inf
           KeepAliveTimeout: Inf

    Specify the custom HTTP options to authenticate the OSLC client myClient.

    setHttpOptions(myClient,opts);

    Create a custom authentication callback function called myCustomLoginProvider.

    function [success,cookies] = myCustomLoginProvider(server,options)
    
    end

    Register the custom authentication callback function with the OSLC client object.

    setCustomLoginProvider(myClient,myCustomLoginProvider);

    Authenticate the OSLC client object.

    login(myClient);

    Input Arguments

    collapse all

    OSLC client, specified as an oslc.Client object.

    Custom authentication callback function name, specified as a character vector.

    Example: 'myCustomLoginProvider'

    Tips

    • If your authentication process requires a particular set of HTTP options, you can either:

      • Construct a matlab.net.http.HTTPOptions object and assign it to your OSLC client by using setHttpOptions, which passes the HTTP options to your custom authentication callback function.

      • Construct the HTTP options internally in your custom authentication callback function.

    • If you want to preconfigure the login process with credentials or use a particular authentication scheme, you can create a matlab.net.http.Credentials object and include it with a matlab.net.http.HTTPOptions object that you assign to the OSLC client object. For more information, see Server Authentication.

      Note

      Depending on the authentication method used by your server, your custom authentication callback function might also have to satisfy authentication requirements. For example, you might have to mimic the form-based authentication required by your authentication server.

    • You can unregister all callbacks from an OSLC client object myClient by entering:

      setCustomLoginProvider(myClient,'');

    Version History

    Introduced in R2021b