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
- Passed as an argument to
new/2
- Environment variable
NIMRAG_USERNAME
- Read from file
{{config_path}}/nimrag/credentials.json
- Passed as an argument to
password:
- Passerd as an argument to
new/2
- Environment variable
NIMRAG_PASSWORD
- Environment variable
NIMRAG_PASSWORD_FILE
with a path to a file containing the password - Environment variable
NIMRAG_PASSWORD_COMMAND
with a command that will output the password - Read from file
{{config_path}}/credentials.json
(XDG_CONFIG_HOME
)
- Passerd as an argument to
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
See read_oauth1_token/0
for details.
Reads OAuth2 token from {{config_path}}/oauth2_token.json
Reads previously stored OAuth tokens
Types
Functions
@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