Reputation: 597
I configured the service as mentioned above:
Plugins.Add(new CorsFeature(
allowCredentials: true,
allowedMethods: "GET, POST, PUT, DELETE, OPTIONS",
allowedHeaders: "Content-Type, Allow, Authorization, Origin",
allowOriginWhitelist: new[]
{
"http://localhost:4200",
"http://localhost:63342",
"http://localhost:63342",
"http://localhost:3000",
"http://my.site.com"
}));
and I have 2 functions Login() and GetContacts()
class AppComponent {
***
constructor(){
this.client = new JsonServiceClient("http://my.site.com");
}
async Login(){
var auth = new wbs.Authenticate();
auth.UserName = this.username;
auth.Password = this.password;
var authResponse = await this.client.post(auth);
console.log(authResponse);
}
async GetContacts(){
try {
this.contacts = await this.client.post(new wbs.Contacts_Get());
console.log(this.contacts);
} catch(e) {
this.contacts = [];
console.log("Failed to get:", e.responseStatus);
}
}
}
"servicestack-client": "0.0.36",
I call these functions in turn:
1. Login()
2. ContactsGet()
if I run locally on IIS express works, but when I deploy to IIS server it's not working. The login runs fine, but in Internet explorere and Safari ContactsGet fails, it returns status 401, but works in Chrome.
Help please in what my error? Thanks!
IIS settings
UPDATE
var authFeature = new AuthFeature(
() => new MyUserSession(),
new[] { new MyCredentialsAuthProvider()
});
public class MyCredentialsAuthProvider : CredentialsAuthProvider {
private Userslogic users => Userslogic.Instance;
public override bool TryAuthenticate(IServiceBase authService, string userName, string password) {
if (!users.CheckUserNameAndPassword(userName, password))
return false;
var session = authService.GetSession(false);
session.IsAuthenticated = true;
return true;
}
}
AuthRequet:
Upvotes: 1
Views: 286
Reputation: 597
In the research of the issue revealed that the problem is on the client and not the server ServiceStack, such restrictions have browsers IE and Safari.
Upvotes: 0
Reputation: 143389
Your issue is because the client does not send Cookies with the request and it's not sending them because your CORS configuration is invalid, the allowOriginWhitelist
URLs need to match exactly with the hostname that the request is sent to, in this case is http://109.120.152.165
.
Whenever subsequent requests in a HTTP Client do not honor the Set-Cookie
Response Headers of the previous request your CORS configuration is invalid and you need to investigate why that is.
Upvotes: 1