Mix Task (Advanced)
Generate client config
The hubic mix task makes requests to the Hubic Api on the user's behalf to get details
such as the referesh token and then generates a configuration which can copied and pasted into config.exs
.
The environment variables generated by the task are automatically save to a .env
file. It is best to ensure that this file is outside
version control.
Shell input:
mix hubic \
--login=<login> \
--password=<password> \
--clientid=<client_id> \
--clientsecret=<client_secret> \
--redirecturi='http://localhost:4000/' \
--elixirappname='my_app' \
--elixirclientname='HubicClient'
login
: username/nic_handle for logging into hubic.password
: password for logging into hubic.elixirappname
: corresponds to theotp_app
name in the elixir application.clientid
: the client id for the application. Created inside the hubic website.clientsecret
: the client secret for the application. Created inside the hubic website.redirecturi
: defaults tohttp://localhost:4000/
when absent.clientname
:" The client name to be used in the elixir application, egMyApp.HubicClient
.
Shell Output:
config :my_app, MyApp.HubicClient,
hubic: [
client_id: System.get_env("MY_APP_HUBIC_CLIENT_CLIENT_ID"),
client_secret: System.get_env("MY_APP_HUBIC_CLIENT_CLIENT_SECRET"),
refresh_token: System.get_env("MY_APP_HUBIC_CLIENT_REFRESH_TOKEN"),
redirect_uri: System.get_env("MY_APP_HUBIC_CLIENT_REDIRECT_URI") || "http://localhost:4000/"
]
Terms explained:
MY_APP_HUBIC_CLIENT_CLIENT_ID
: The system environment variable name for the client id.MY_APP_HUBIC_CLIENT_CLIENT_SECRET
: The system environment variable name for the client secret.MY_APP_HUBIC_CLIENT_REFRESH_TOKEN
: The system environment variable name for the latest client resresh token.MY_APP_HUBIC_CLIENT_REDIRECT_URI
: The system environment variable name for the hubic redirect uri.Copy the configuration outputted by the commandline to
config.exs
.The enviroment variables are saved to a file called
.env
automatically by the mix task. Do not add the.env
file to version control. Add the variables to the system environment by running the command or some other commands as appropriate to the deployment method.
source .env