IPG.RestSharp.BearerAuthenticator 1.0.2

dotnet add package IPG.RestSharp.BearerAuthenticator --version 1.0.2
NuGet\Install-Package IPG.RestSharp.BearerAuthenticator -Version 1.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="IPG.RestSharp.BearerAuthenticator" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add IPG.RestSharp.BearerAuthenticator --version 1.0.2
#r "nuget: IPG.RestSharp.BearerAuthenticator, 1.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install IPG.RestSharp.BearerAuthenticator as a Cake Addin
#addin nuget:?package=IPG.RestSharp.BearerAuthenticator&version=1.0.2

// Install IPG.RestSharp.BearerAuthenticator as a Cake Tool
#tool nuget:?package=IPG.RestSharp.BearerAuthenticator&version=1.0.2

IPG RestSharp BearerAuthenticator

Simple class that inherits RestSharp's IAuthenticator and implements Bearer Authentication in a RestRequest / RestClient.

Description

RestSharp doesn't support bearer authentication out-of-the-box as it does for other common authentication mechanisms (such as basic auth).

IPG.RestSharp.BearerAuthenticator is a simple class that inherits IAuthenticator, allows you to specify an access token and then implements Bearer authentication via the 'Authorization' header.

Usage

using IPG.RestSharp.BearerAuthenticator;
...

// Create a rest client
var client = new RestClient("http://example.com");

// Set the client's authenticator property to an instance of the BearerAuthenticator
// class which has had the access token passed into it's constructor
client.Authenticator = new BearerAuthenticator("<my-secret-token>");

// Continue using the rest client as normal
...

You can also pass in an instantiated version of the class wherever there are higher level absractions that accept an IAuthenticator parameter (such as in 3rd party libraries).

Dynamic evaluation of token

In some situations it might be helpful to 'evaluate' the token value only at the point it's needed by the rest client (i.e. the Authenticate method). This could occur in a scenario where you're using dependency injection and the whole service provider graph is configured on program instantiation but when the access token is not know until further processing has occured. This is supported by the use of overloaded constructor accepting a Func <string> parameter.

Installation

Use the Nuget Package Manager to install the library. Nuget package name is "IPG.RestSharp.BearerAuthenticator". You can also instal via running the following in the Package Manager Console:

Install-Package IPG.RestSharp.BearerAuthenticator
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net452 is compatible.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 716 8/10/2021
1.0.1 557 8/10/2021
1.0.0 359 8/6/2021