I am new to Elixir and decided to create my very first Elixir application using the Phoenix framework. My application uses github for logging and storing my application’s client id and client secret in an environment variable became a requirement when I wanted to push my repo to github publicly.

Luckily, Elixir makes it very easy to store and access environment variables. In my config.exs file I had the following configuration for github using Ueberauth for authentication.

config :ueberauth, Ueberauth.Strategy.Github.OAuth,
client_id: System.get_env("GITHUB_CLIENT_ID"),
client_secret: System.get_env("GITHUB_CLIENT_SECRET")

I then created a .env file under the config directory with the following:

export GITHUB_CLIENT_ID="<My Github client id>"
export GITHUB_CLIENT_SECRET="<My Github Client Secret>"

I also added config/.env to my .gitignore file to make sure my client id and secret are not committed and pushed to my public repo. Now before running mix phoenix.server I need to run source config/.env

About

Ahmed Hawas

Software Developer (www.ahmedhawas.com)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store