Menu

Security pattern

Security pattern

Security pattern indicates that web services required authorization when accessing.

Configuration example


<Pattern name="Security">
</Pattern>

Configuration parameters

Actually, there are no parameters.

Implementing your authentication method

GL generates a partial class CustomCredentialsAuthProvider in source file DomainServicesHost.cs. You should implement only 2 methods for using security.

  1. Create a new file of partial class, i.e. CustomCredentialsAuthProvider.cs
  2. Add following methods to class body and implement your authentication method. See more details and exemples on ServiceStack documentation


public partial class CustomCredentialsAuthProvider : CredentialsAuthProvider
{
    public override bool TryAuthenticate(IServiceBase authService, string userName, string password)
    {
        //Add here your custom auth logic (database calls etc)
        bool userAuthentified = ...
        return userAuthentified; //
    }

    public override void OnAuthenticated(IServiceBase authService, IAuthSession session, IOAuthTokens tokens, Dictionary<string, string> authInfo)
    {
        //Important: You need to save the session
        authService.SaveSession(session, SessionExpiry);
    }
}

Use case code exemple


WebClientFactory.AuthProviderName = CredentialsAuthProvider.Name;
WebClientFactory.UserName = "john"; // User name should have 3 or more characters
WebClientFactory.Password = "password";
WebClientFactory.RemeberMe = true;
Currency currency = Currency.GetByCode("EUR");
Assert.IsNotNull(currency, "Authetification failed");

Related

Wiki: Detailed guidelines

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.