Hi community and M-Files,
I am tasked to design new Web API which should download and open documents from M-Files. Our users are not satisfied with links created by M-Files.
I am struggling to authenticate user with SSO M-Files functionality. Basically, I have .NET 6 Web Api running under own app pool. It tries to authenticate over SSO functionality:
public async Task AuthenticateUsingSSO(string vaultGuid) { // Build a request to WebServiceSSO.aspx. var request = new RestRequest($"/WebServiceSSO.aspx?popup=1&vault={vaultGuid}"); try { // Execute the request. var response = await _client.GetAsync(request); if (response.StatusCode == HttpStatusCode.Unauthorized) throw new AuthenticationException(response.Content, response.ErrorMessage); // Populate our cookie container with the cookies (i.e. session tokens) // returned by the request to WebServiceSSO.aspx. if (response.Cookies != null) { foreach (var cookie in response.Cookies.AsEnumerable()) { _client.CookieContainer.Add(new Cookie(cookie.Name, cookie.Value, cookie.Path, cookie.Domain)); } } } catch (Exception ex) { throw new AuthenticationException(ex); } }
When I execute "await _client.GetAsync(request);", I already starts getting 401 Unauthorized error.
RestClient is initialized like this:
return new RestClient( new RestClientOptions { Credentials = CredentialCache.DefaultNetworkCredentials, BaseUrl = new Uri(_baseUrl) } );
This should pick up credentials from executing user.
I am following examples from M-Files client library from Git and I am using RestSharp library.
Has anyone implemented windows authentication / SSO in IIS? Basically taking user credentials with windows authentication and logging with those credentials over SSO API from M-Files.
I would appreciate any sharing in this area. It would be also great to know if someone used .NET Core or .NET 6 to implement this one.
Best regards,
Dejan