HttpFs.Auth0
HttpFs.Auth0 provides constructs which make it easier to use Auth0 when interacting with protected APIs.
This library focuses on server-to-server interactions, where one service needs to authenticate itself to
another service in order to gain access to a provided resource. This library also includes a
TokenCache
for transiently caching ID tokens while they
remain valid.
HttpFs.Auth0 also supports a knock-first workflow, where an attempt is made to interact with a resource first.
In this case, if the resource sends back a 401 Unauthorized
response, then the request can be retried after
(possibly generating and) adding the Auth0 token to the request.
PM> Install-Package HttpFs.Auth0
Example
The following shows a simple flow for authenticating with an API. It uses the Auth0 demo app credentials from their SSO Heroku application. You can get your own Auth0 account to test with by going to https://www.auth0.com.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: |
|
The next example demonstrates how to set up a token cache and validate the client parameters returned by the protected resource against a whitelist of known client parameters. This helps to ensure that a malicious resource can't trick you into sending your credentials to a malicious authentication server.
The token cache helps to reduce the load on the Authentication API, keeping the token in memory while the token remains valid.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: |
|
Logging
This library uses the logging façade provided by Http.Fs
under then
HttpFs.Logging
namespace. You can enable logging by initializing the
façade and hooking it to your logging framework of choice.
Setting up logging:
1: 2: 3: 4: 5: 6: |
|
Example logs:
|
Note that you may see the following warning from Hopac. We are working to make
this warning go away in a future version, but you should experience no adverse
effects as the run
utilized by Logary returns very quickly.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: |
|
Samples & documentation
The API reference is automatically generated from Markdown comments in the library implementation.
- API Reference contains automatically generated documentation for all types, modules and functions in the library. This includes additional brief samples on using most of the functions.
Contributing and copyright
The project is hosted on GitHub where you can report issues, fork the project and submit pull requests. If you're adding a new public API, please also consider adding samples that can be turned into a documentation. You might also want to read the library design notes to understand how it works.
The library is available under Apache 2.0 license, which allows modification and redistribution for both commercial and non-commercial purposes. For more information see the License file in the GitHub repository.
from Hopac
Full name: Hopac.Hopac.run
module Job
from Hopac
--------------------
type Job<'T> =
Full name: Hopac.Job<_>
Full name: Hopac.Job.unit
module Choice
from YoLo
--------------------
type Choice<'T1,'T2> =
| Choice1Of2 of 'T1
| Choice2Of2 of 'T2
Full name: Microsoft.FSharp.Core.Choice<_,_>
--------------------
type Choice<'T1,'T2,'T3> =
| Choice1Of3 of 'T1
| Choice2Of3 of 'T2
| Choice3Of3 of 'T3
Full name: Microsoft.FSharp.Core.Choice<_,_,_>
--------------------
type Choice<'T1,'T2,'T3,'T4> =
| Choice1Of4 of 'T1
| Choice2Of4 of 'T2
| Choice3Of4 of 'T3
| Choice4Of4 of 'T4
Full name: Microsoft.FSharp.Core.Choice<_,_,_,_>
--------------------
type Choice<'T1,'T2,'T3,'T4,'T5> =
| Choice1Of5 of 'T1
| Choice2Of5 of 'T2
| Choice3Of5 of 'T3
| Choice4Of5 of 'T4
| Choice5Of5 of 'T5
Full name: Microsoft.FSharp.Core.Choice<_,_,_,_,_>
--------------------
type Choice<'T1,'T2,'T3,'T4,'T5,'T6> =
| Choice1Of6 of 'T1
| Choice2Of6 of 'T2
| Choice3Of6 of 'T3
| Choice4Of6 of 'T4
| Choice5Of6 of 'T5
| Choice6Of6 of 'T6
Full name: Microsoft.FSharp.Core.Choice<_,_,_,_,_,_>
--------------------
type Choice<'T1,'T2,'T3,'T4,'T5,'T6,'T7> =
| Choice1Of7 of 'T1
| Choice2Of7 of 'T2
| Choice3Of7 of 'T3
| Choice4Of7 of 'T4
| Choice5Of7 of 'T5
| Choice6Of7 of 'T6
| Choice7Of7 of 'T7
Full name: Microsoft.FSharp.Core.Choice<_,_,_,_,_,_,_>
Full name: Index.Choice.getOrFail
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.failwithf
type Uri =
new : uriString:string -> Uri + 5 overloads
member AbsolutePath : string
member AbsoluteUri : string
member Authority : string
member DnsSafeHost : string
member Equals : comparand:obj -> bool
member Fragment : string
member GetComponents : components:UriComponents * format:UriFormat -> string
member GetHashCode : unit -> int
member GetLeftPart : part:UriPartial -> string
...
Full name: System.Uri
--------------------
Uri(uriString: string) : unit
Uri(uriString: string, uriKind: UriKind) : unit
Uri(baseUri: Uri, relativeUri: string) : unit
Uri(baseUri: Uri, relativeUri: Uri) : unit
Full name: Index.Uri.isAbsolute
Full name: Index.Uri.toString
from HttpFs.Logging
Full name: HttpFs.Logging.Global.initialise
Full name: HttpFs.Logging.Global.DefaultConfig
type ConsoleWindowTarget =
interface Logger
new : minLevel:LogLevel * ?formatter:(Message -> string) * ?colourise:bool * ?originalColor:ConsoleColor * ?consoleSemaphore:Object -> ConsoleWindowTarget
Full name: HttpFs.Logging.ConsoleWindowTarget
--------------------
new : minLevel:LogLevel * ?formatter:(Message -> string) * ?colourise:bool * ?originalColor:ConsoleColor * ?consoleSemaphore:Object -> ConsoleWindowTarget
interface
abstract member log : LogLevel -> (LogLevel -> Message) -> unit
abstract member logSimple : Message -> unit
abstract member logWithAck : LogLevel -> (LogLevel -> Message) -> Async<unit>
end
Full name: HttpFs.Logging.Logger
from HttpFs
Full name: Index.cp
union case ClientId.ClientId: string -> ClientId
--------------------
module ClientId
from HttpFs.Auth0.Types
--------------------
type ClientId = | ClientId of string
Full name: HttpFs.Auth0.Types.ClientId
Full name: HttpFs.Auth0.Types.ClientId.create
Full name: Index.ac
Full name: Index.atJ
from HttpFs.Auth0
Full name: HttpFs.Auth0.Authentication.createRequest
Full name: HttpFs.Auth0.Authentication.tryAuthenticate
inherit Job<'T>
Full name: Hopac.Alt<_>
Full name: Hopac.Alt.afterFun
module AuthenticationResult
from HttpFs.Auth0.Authentication
--------------------
type AuthenticationResult =
| AuthOk of a0token: Auth0Token
| AuthFail of failure: Auth0ApiFailure
Full name: HttpFs.Auth0.Authentication.AuthenticationResult
Full name: HttpFs.Auth0.Authentication.AuthenticationResult.toChoice
Full name: Index.at
Full name: Hopac.Hopac.run
module Choice
from Index
--------------------
module Choice
from YoLo
--------------------
type Choice<'T1,'T2> =
| Choice1Of2 of 'T1
| Choice2Of2 of 'T2
Full name: Microsoft.FSharp.Core.Choice<_,_>
--------------------
type Choice<'T1,'T2,'T3> =
| Choice1Of3 of 'T1
| Choice2Of3 of 'T2
| Choice3Of3 of 'T3
Full name: Microsoft.FSharp.Core.Choice<_,_,_>
--------------------
type Choice<'T1,'T2,'T3,'T4> =
| Choice1Of4 of 'T1
| Choice2Of4 of 'T2
| Choice3Of4 of 'T3
| Choice4Of4 of 'T4
Full name: Microsoft.FSharp.Core.Choice<_,_,_,_>
--------------------
type Choice<'T1,'T2,'T3,'T4,'T5> =
| Choice1Of5 of 'T1
| Choice2Of5 of 'T2
| Choice3Of5 of 'T3
| Choice4Of5 of 'T4
| Choice5Of5 of 'T5
Full name: Microsoft.FSharp.Core.Choice<_,_,_,_,_>
--------------------
type Choice<'T1,'T2,'T3,'T4,'T5,'T6> =
| Choice1Of6 of 'T1
| Choice2Of6 of 'T2
| Choice3Of6 of 'T3
| Choice4Of6 of 'T4
| Choice5Of6 of 'T5
| Choice6Of6 of 'T6
Full name: Microsoft.FSharp.Core.Choice<_,_,_,_,_,_>
--------------------
type Choice<'T1,'T2,'T3,'T4,'T5,'T6,'T7> =
| Choice1Of7 of 'T1
| Choice2Of7 of 'T2
| Choice3Of7 of 'T3
| Choice4Of7 of 'T4
| Choice5Of7 of 'T5
| Choice6Of7 of 'T6
| Choice7Of7 of 'T7
Full name: Microsoft.FSharp.Core.Choice<_,_,_,_,_,_,_>
Full name: Index.respJ
module Request
from HttpFs.Client
--------------------
type Request =
{url: Uri;
method: HttpMethod;
cookiesEnabled: bool;
autoFollowRedirects: bool;
autoDecompression: DecompressionScheme;
headers: Map<string,RequestHeader>;
body: RequestBody;
bodyCharacterEncoding: Encoding;
queryStringItems: Map<QueryStringName,QueryStringValue>;
cookies: Map<CookieName,Cookie>;
...}
Full name: HttpFs.Client.Request
Full name: HttpFs.Client.Request.createUrl
from HttpFs.Auth0
Full name: HttpFs.Auth0.Auth0Client.addAuth0TokenHeader
Full name: HttpFs.Client.getResponse
Full name: Index.cep
module CacheExpirationParameters
from HttpFs.Auth0
--------------------
type CacheExpirationParameters
Full name: HttpFs.Auth0.CacheExpirationParameters
Full name: HttpFs.Auth0.CacheExpirationParameters.create'
Full name: Index.tc
module TokenCache
from HttpFs.Auth0
--------------------
type TokenCache
Full name: HttpFs.Auth0.TokenCache
Full name: HttpFs.Auth0.TokenCache.create
Full name: Index.credentialMap
module Map
from YoLo
--------------------
module Map
from Microsoft.FSharp.Collections
--------------------
type Map<'Key,'Value (requires comparison)> =
interface IEnumerable
interface IComparable
interface IEnumerable<KeyValuePair<'Key,'Value>>
interface ICollection<KeyValuePair<'Key,'Value>>
interface IDictionary<'Key,'Value>
new : elements:seq<'Key * 'Value> -> Map<'Key,'Value>
member Add : key:'Key * value:'Value -> Map<'Key,'Value>
member ContainsKey : key:'Key -> bool
override Equals : obj -> bool
member Remove : key:'Key -> Map<'Key,'Value>
...
Full name: Microsoft.FSharp.Collections.Map<_,_>
--------------------
new : elements:seq<'Key * 'Value> -> Map<'Key,'Value>
Full name: Microsoft.FSharp.Collections.Map.ofList
Full name: Index.prefixWhitelist
Full name: Index.tryGetCredentialsJob
{AuthenticationHost: string;
ClientId: ClientId;}
Full name: HttpFs.Auth0.Types.ClientParams
module List
from YoLo
--------------------
module List
from Microsoft.FSharp.Collections
--------------------
type List<'T> =
| ( [] )
| ( :: ) of Head: 'T * Tail: 'T list
interface IEnumerable
interface IEnumerable<'T>
member GetSlice : startIndex:int option * endIndex:int option -> 'T list
member Head : 'T
member IsEmpty : bool
member Item : index:int -> 'T with get
member Length : int
member Tail : 'T list
static member Cons : head:'T * tail:'T list -> 'T list
static member Empty : 'T list
Full name: Microsoft.FSharp.Collections.List<_>
Full name: Microsoft.FSharp.Collections.List.tryPick
module Option
from YoLo
--------------------
module Option
from Microsoft.FSharp.Core
Full name: Microsoft.FSharp.Core.Option.bind
Full name: Microsoft.FSharp.Collections.Map.tryFind
Full name: Hopac.Job<_>
Full name: Hopac.Job.result
Full name: Index.tryAuthenticateClient
Full name: HttpFs.Auth0.Authentication.tryAuthenticateFromSource
Full name: Index.tryGetAuthToken
Full name: HttpFs.Auth0.TokenCache.tryGetTokenWithFill
Full name: Index.respCToStringJ
module Response
from HttpFs.Client
--------------------
type Response =
{statusCode: int;
contentLength: int64;
characterSet: CharacterSet;
cookies: Map<string,string>;
headers: Map<ResponseHeader,string>;
expectedEncoding: Encoding option;
responseUri: Uri;
body: Stream;
luggage: IDisposable option;}
interface IDisposable
override ToString : unit -> string
static member private ofHttpResponse : response:HttpWebResponse -> Response
Full name: HttpFs.Client.Response
Full name: HttpFs.Client.Response.readBodyAsString
val string : value:'T -> string
Full name: Microsoft.FSharp.Core.Operators.string
--------------------
type string = String
Full name: Microsoft.FSharp.Core.string
Full name: Index.respStrA
Full name: HttpFs.Auth0.Auth0Client.tryGetResponseWithRetryOnAuthRequired
Full name: Hopac.Alt.afterJob
static member CommandLine : string
static member CurrentDirectory : string with get, set
static member Exit : exitCode:int -> unit
static member ExitCode : int with get, set
static member ExpandEnvironmentVariables : name:string -> string
static member FailFast : message:string -> unit + 1 overload
static member GetCommandLineArgs : unit -> string[]
static member GetEnvironmentVariable : variable:string -> string + 1 overload
static member GetEnvironmentVariables : unit -> IDictionary + 1 overload
static member GetFolderPath : folder:SpecialFolder -> string + 1 overload
...
nested type SpecialFolder
nested type SpecialFolderOption
Full name: System.Environment
member CreateCopy : unit -> ExecutionContext
member Dispose : unit -> unit
member GetObjectData : info:SerializationInfo * context:StreamingContext -> unit
static member Capture : unit -> ExecutionContext
static member IsFlowSuppressed : unit -> bool
static member RestoreFlow : unit -> unit
static member Run : executionContext:ExecutionContext * callback:ContextCallback * state:obj -> unit
static member SuppressFlow : unit -> AsyncFlowControl
Full name: System.Threading.ExecutionContext