-
Notifications
You must be signed in to change notification settings - Fork 0
Security pattern
Security pattern indicates that web services required authorization when accessing.
<Pattern name="Security">
</Pattern>
Actually, there are no parameters.
GL generates a partial class CustomCredentialsAuthProvider in source file DomainServicesHost.cs. You should implement only 2 methods for using security.
-
Create a new file of partial class, i.e.
CustomCredentialsAuthProvider.cs -
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); }}
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");