matlab.net.http.Credentials Class
Namespace: matlab.net.http
Superclasses: handle
Credentials for authenticating HTTP requests
Description
The Credentials
class specifies authentication credentials for sending a
request message. Specify a Credentials
object in an HTTPOptions
object.
The RequestMessage.send
method uses credentials to respond to
authentication challenges from servers or proxies. The authentication challenge is in an
AuthenticateField
header field and specifies
one or more authentication schemes that the server or proxy accepts to satisfy the
request.
The behavior depends on the authentication scheme. In general, MATLAB® searches the vector of Credentials
objects for one that applies
to the request URI and which supports the specified authentication scheme. MATLAB then resends the original request with the appropriate credentials in an AuthorizationField
header. If multiple credentials apply, then MATLAB uses the most specific Credentials
object for the strongest
scheme. If duplicate Credentials
objects exist, then MATLAB uses the first one.
To see what authentication schemes MATLAB implements automatically, see AuthenticationScheme
. If the server requires other schemes, or you do not supply
credentials for the required scheme, then the authentication response message returns a
StatusCode of 401
or 407. In this case, you must implement the appropriate response yourself.
For schemes that do not require Username
and
Password
properties, such as NTLM on Windows®, you can use a default Credentials
object. A default
Credentials
object has default or empty properties and applies to all
supported schemes and URIs. Your authorization credentials come from information, such as
Kerberos tickets, that are stored in your system when you log in. To constrain the conditions
under which a particular scheme is used, you can specify additional properties, such as
Scope and
Realm. For
example, set these values to use NTLM for some URLs and Kerberos for others and reject
authentication requests from servers that do not match those URLs and schemes.
For schemes that require Username
and Password
properties, if MATLAB authenticates with a Credentials
object, then MATLAB saves the results in this object. MATLAB can apply these credentials on subsequent requests without waiting for an
authentication challenge from the server. To take advantage of shortcut, provide the same
Credentials
object on subsequent requests in the same or other
HTTPOptions
objects.
Credentials
objects are handle objects and internally accumulate
information about prior successful authentications. Therefore, you can reuse the information
for subsequent messages. If you insert this object into multiple HTTPOptions
objects, then the Credentials
object might be updated upon each use. If you
copy Credentials
using its copy
method, then MATLAB copies only the visible properties that you set, and not the internal
state.
The matlab.net.http.Credentials
class is a handle
class.
Creation
Description
obj = matlab.net.http.Credentials(Name,Value)
creates HTTP
credentials with additional properties specified by one, or more name-value pair
arguments. Name
is the property name and Value
is
the corresponding value. You can specify several name-value pair arguments in any order as
Name1,Value1,...,NameN,ValueN
. Unspecified properties are set to
their default values.
If you call this constructor with no arguments, then the Credentials
object applies to and thus permits authentication for all URIs and all authentication
schemes. However, the object works only for schemes that do not require a user name or
password. For example, on Windows, the object enables NTLM and Kerberos authentication using the credentials
of the logged-in user.
Properties
Examples
Version History
Introduced in R2016b