Skip to content

EnsureAuthenticated

Authenticates the client with the specified service and scope if not already authenticated.

1
myRestClient.EnsureAuthenticated(service: string):RestClient

Authenticates the client with the specified service and scope if not already authenticated.

1
myRestClient.EnsureAuthenticated(service: string, scope: string):RestClient

Authenticates the client with the specified service, scope, and identity if not already authenticated.

1
myRestClient.EnsureAuthenticated(service: string, scope: string, identity: ( string | Identity )):RestClient

Parameters

string service
    The name of the service to authenticate with.

string scope
    The scope of the authentication context.

( string | Identity ) identity
    The identity to impersonate. Can be an Identity instance or its ID.

Returns

The current RestClient instance. The current RestClient instance. The current RestClient instance.

Remarks

The scope of authentication is based on the service parameter. Refer to the service documentation for details.
This method attempts server-to-server authentication if configured for the service. Otherwise, user consent must have been previously granted.
If authentication fails, an error is thrown. Use a try-catch block to handle potential authentication failures.

Example

1
2
3
4
5
var scopes = 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email';

var client = $Rest.Create('https://www.googleapis.com/oauth2/v2/userinfo');

var result = client.EnsureAuthenticated('Google',scopes, $Initiator).ExecuteJson();

The scope of authentication is based on the service parameter. Refer to the service documentation for details.
This method attempts server-to-server authentication if configured for the service. Otherwise, user consent must have been previously granted.
If authentication fails, an error is thrown. Use a try-catch block to handle potential authentication failures.

Example

1
2
3
4
5
var scopes = 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email';

var client = $Rest.Create('https://www.googleapis.com/oauth2/v2/userinfo');

var result = client.EnsureAuthenticated('Google',scopes, $Initiator).ExecuteJson();

The scope of authentication is based on the service parameter. Refer to the service documentation for details.
This method attempts server-to-server authentication if configured for the service. Otherwise, user consent must have been previously granted.
If authentication fails, an error is thrown. Use a try-catch block to handle potential authentication failures.

Example

1
2
3
4
5
var scopes = 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email';

var client = $Rest.Create('https://www.googleapis.com/oauth2/v2/userinfo');

var result = client.EnsureAuthenticated('Google',scopes, $Initiator).ExecuteJson();

See Also