41 lines
1.1 KiB
Forth
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
|
|
}
|