2
votes

I am trying to use the OData type provider with a Sharepoint site that is protected by forms authentication. Connecting with a browser presents the browser embedded "auth form" to authenticate.

Using the type provider I am unable to connect to it, and I can't find a way to provide credentials:

enter image description here

I have seen that you can provide credentials after this step, like this:

let db = service.GetDataContext() in
    db.Credentials <-
        (NetworkCredential("user_name", "password", "domain") :> ICredentials)

But I can't even get to that point, both at design time and at runtime the code throws the 401 error as seen in the screenshot.

So, how am I supposed to connect to an OData service that is behind forms auth?

Thanks.

1

1 Answers

1
votes

There are a couple things going on here. First, the 401 unauthorized result is what the login page sends to your browser. So even if your script could load that login page, it would still see it as a 401 and you'd have to handle that somehow.

But the real problem is that your browser's cookies are completely separate from the F# environment (or any other program, really). You need to send along the authorization token with the HTTP request so that the server knows it's you. This means you'll likely have to provide your own login interface that knows how to use that form, save the cookies, and pass them along with your requests.

I'm not sure how to accomplish this with type providers but this other question might help: Send Authorization cookie when calling OData service