unchase / Unchase.Odata.Connectedservice

:scroll: A Visual Studio extension for connecting to OData services with generating client-side C# proxy-classes
Apache License 2.0
44 stars 13 forks source link

FEATURE: Bearer Token #29

Closed encinitasLab closed 4 years ago

encinitasLab commented 4 years ago

I see the ability to add network credentials but would be great if there was an option to add header for bearer token, or let me know if it is capable and I just missed it.

unchase commented 4 years ago

You can add Authorization header like this:

//...
// add there your OData Uri
var container = new DefaultContainer(new Uri("https://services.odata.org/V4/(S(qc322lduoxrqt13nhydbdcvx))/TripPinServiceRW/")); 
container.Configurations.RequestPipeline.OnMessageCreating = (args) =>
{
    var request = new HttpWebRequestMessage(args);

    //Setting the values in the Authorization header
    request.SetHeader("Authorization", "Bearer <your_token>");

    return request;
};
//...