Options
All
  • Public
  • Public/Protected
  • All
Menu

Authentication API.

Centralises storage and mangement of authentication to Hivehome's REST API.

Hierarchy

  • Auth

Index

Constructors

Properties

Methods

Constructors

constructor

  • new Auth(email: string): Auth
  • Parameters

    • email: string

    Returns Auth

Properties

token

token: undefined | string

Current authentication token

Methods

checkTokenAndRefresh

  • checkTokenAndRefresh(): Promise<Auth>
  • Check token expiry.

    Refresh the current auth token if the token will expire within the next 15 mins, or the remaining validity period is below 1/3 of the original duration.

    This is used internally for all REST calls: As long as 3 requests are made within the original validity period of the token being issued, the authentication token will always remain active.

    If the token does expire, users will have be re-authenticated using the oboarding authentication flow, provided by Auth.login.

    Returns Promise<Auth>

login

  • login(password: string): Promise<Auth>
  • Authenticate against the REST API using your account email + password This is the only time a user's email + password are required for authentication. The Auth.refresh method can be used to ensure the auth token is perpetually active.

    note

    Currently, authentication tokens are valid for 1hour.

    example
    import { Hivehome } from 'node-hivehome';
    
    (async () => {
      const hive = await new Hivehome('hello@example.com');
    
      await hive.auth.login('supersecretpassword');
      // `hive` object is now authenticated
    })()
    
    todo

    Add support for MFA

    todo

    Add support for providing the password via an ENV var

    Parameters

    • password: string

    Returns Promise<Auth>

refresh

  • refresh(): Promise<Auth>
  • Refresh authentication token. Current token(s) must still be active and not expired.

    example
    import { Hivehome } from 'node-hivehome';
    
    (async () => {
      const hive = await new Hivehome('hello@example.com');
    
      // ... login as shown .login() flow
    
      // do some stuff (time passes..)
    
      await hive.auth.refresh();
      // `hive` object is now authenticated with a newly issued token
    })()
    

    Returns Promise<Auth>

Generated using TypeDoc