Skip to content

Instantly share code, notes, and snippets.

@jamessdixon
Created February 21, 2019 01:19
Show Gist options
  • Save jamessdixon/1731eca1fe77a69b4d68792cd8f11b6b to your computer and use it in GitHub Desktop.
Save jamessdixon/1731eca1fe77a69b4d68792cd8f11b6b to your computer and use it in GitHub Desktop.
Auth0 with F#
namespace sameroom.mobile.iOS
open System
open Xamarin.Forms
open sameroom.mobile
open Auth0.OidcClient
type LoginParameters = { audience : string }
type AuthenticationService() =
let authenticate =
async {
let options = new Auth0ClientOptions()
options.Domain <- Support.authenticationConfig.Domain
options.ClientId <- Support.authenticationConfig.ClientId
let client = new Auth0Client(options)
//let result = cient.LoginAsync({ audience = Support.authenticationConfig.Audience })
let! result = client.LoginAsync({ audience = Support.authenticationConfig.Audience }) |> Async.AwaitTask
return result
}
interface IAuthenticationService with
member this.Authenticate =
let result = authenticate |> Async.RunSynchronously
match result.IsError with
| true ->
AuthenticationResult.Bad {Error=result.Error}
| false ->
AuthenticationResult.Good {IdToken = result.IdentityToken; AccessToken=result.AccessToken; UserClaims=result.User.Claims;}
module AuthenticationService =
[<assembly: Dependency(typeof<AuthenticationService>)>]
do()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment