Files
puregym-unofficial-dotnet/PureGym.App/Authenticate.fs
Smaug123 42eb1f7726
All checks were successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/all-checks-complete Pipeline was successful
Initial commit
2023-10-11 21:16:40 +01:00

41 lines
1.1 KiB
Forth

namespace PureGym.App
open Argu
open System
open PureGym
type GetTokenArg =
| [<ExactlyOnce>] User_Email of string
| [<ExactlyOnce>] Pin of string
interface IArgParserTemplate with
member s.Usage =
match s with
| GetTokenArg.Pin _ -> "Eight-digit PureGym user's PIN"
| GetTokenArg.User_Email _ -> "PureGym user's email address"
static member Parse (args : ParseResults<GetTokenArg>) : Result<UsernamePin, ArguParseException> =
try
{
Username = args.GetResult GetTokenArg.User_Email
Pin = args.GetResult GetTokenArg.Pin
}
|> Ok
with :? ArguParseException as e ->
Error e
[<RequireQualifiedAccess>]
module Authenticate =
let run (creds : UsernamePin) =
task {
let! cred = AuthToken.get creds
Console.WriteLine cred.AccessToken
match cred.ExpiryTime with
| None -> ()
| Some expiry -> Console.Error.WriteLine $"Expires at {expiry}"
return 0
}