View Source Nimrag.Credentials (Nimrag v0.1.0)

Holds credentials for authentication. Required only to setup initial OAuth tokens.

Username and password are needed for Nimrag.Auth.login_sso/2.

Multi factor authentication (MFA)

Nimrag supports MFA flow by asking to input code when needed, it's highly recommended that you set up MFA on you Garmin account.

Nimrag tries to provied nice out of box defaults and credentials are obtained in a number of ways:

  • username

    1. Passed as an argument to new/2
    2. Environment variable NIMRAG_USERNAME
    3. Read from file {{config_path}}/nimrag/credentials.json
  • password:

    1. Passerd as an argument to new/2
    2. Environment variable NIMRAG_PASSWORD
    3. Environment variable NIMRAG_PASSWORD_FILE with a path to a file containing the password
    4. Environment variable NIMRAG_PASSWORD_COMMAND with a command that will output the password
    5. Read from file {{config_path}}/credentials.json (XDG_CONFIG_HOME)
  • MFA code - by default it's stdin, but you can provide your own function to read it

You should use {{config_path}}/credentials.json as last resort and in case you do, ensure that the file has limited permissions(600), otherwise you'll get a warning.

What's {{config_path}}?

By default, it's going to be ~/.config/nimrag. You can also supply custom value via config :nimrag, config_fs_path: "/path/to/config" or NIMRAG_CONFIG_PATH. This is the location for OAuth tokens, and optionally credentials.

Created OAuth tokens are stored in {{config_path}}/oauth1_token.json and {{config_path}}/oauth2_token.json. OAuth2 token is valid for around an hour and is automatically refreshed when needed. OAuth1Token is valid for up to 1 year and when it expires, you'll need re-authenticate with username and password.

Summary

Functions

Reads OAuth1 token from {{config_path}}/oauth1_token.json

Reads OAuth2 token from {{config_path}}/oauth2_token.json

Reads previously stored OAuth tokens

Types

@type get_mfa() :: nil | mfa() | (-> {:ok, String.t()} | {:error, atom()})
@type t() :: %Nimrag.Credentials{
  get_mfa: get_mfa(),
  password: nil | String.t(),
  username: nil | String.t()
}

Functions

Link to this function

new(username \\ nil, password \\ nil, get_mfa \\ nil)

View Source
@spec new(
  username :: nil | String.t(),
  password :: nil | String.t(),
  get_mfa :: get_mfa()
) :: t()
@spec read_oauth1_token() :: {:ok, Nimrag.OAuth1Token.t()} | {:error, String.t()}

Reads OAuth1 token from {{config_path}}/oauth1_token.json

See Nimrag.Auth for more details on how to obtain auth tokens.

@spec read_oauth1_token!() :: Nimrag.OAuth1Token.t() | no_return()

See read_oauth1_token/0 for details.

@spec read_oauth2_token() :: {:ok, Nimrag.OAuth2Token.t()} | {:error, String.t()}

Reads OAuth2 token from {{config_path}}/oauth2_token.json

See Nimrag.Auth for more details on how to obtain auth tokens.

@spec read_oauth2_token!() :: Nimrag.OAuth2Token.t() | no_return()
@spec read_oauth_tokens!() ::
  {Nimrag.OAuth1Token.t(), Nimrag.OAuth2Token.t()} | no_return()

Reads previously stored OAuth tokens