Authentication

Learn how to authenticate your requests using BELLATRIX API library.

Example

[TestFixture]
[JwtAuthenticationStrategy(GlobalConstants.JwtToken)]
public class AuthenticationTests : APITest
{
    [Test]
    public void GetAlbumById()
    {
        var request = new RestRequest("api/Albums/10");

        var client = App.GetApiClientService();

        var response = client.Get<Albums>(request);

        Assert.AreEqual(10, response.Data.AlbumId);
    }
}

Explanations

BELLATRIX provides an easy way to authenticate through the usage of few attributes.

[JwtAuthenticationStrategy(GlobalConstants.JwtToken)]

We use JwtToken authentication. The attribute accepts your text tocken. Other authentication strategy attributes:

  • HttpBasicAuthenticationStrategy - user and password.
  • NtlmAuthenticationStrategy - authenticate with the credentials of the currently logged in user, or impersonate a user.
  • OAuth2AuthorizationRequestHeaderAuthenticationStrategy - OAuth 2 authenticator using the authorization request header field.
  • OAuth2UriQueryParameterAuthenticationStrategy - OAuth 2 authenticator using URI query parameter.
  • SimpleAuthenticationStrategy - userKey, user, passwordKey, password.