Skip to content

EnsureAuthenticated

Authenticates the client with the specified service 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 | null )):RestClient

Parameters

string service optional
    The name of the service to authenticate with.

string scope
    The scope of the authentication context.

( string | Identity | null ) identity
    The identity to impersonate, as an Identity object or its ID.

Returns

The current RestClient instance.

Remarks

If authentication fails, an error is thrown, so the following calls can assume an authenticated client.

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.

Examples

Authenticate and call a service in one chain

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

var userInfo = $Rest.Create('https://www.googleapis.com/oauth2/v2/')
    .EnsureAuthenticated('Google', scopes, $Initiator)
    .Request('userinfo')
    .ExecuteJson();

See Also