Skip to content

Repository files navigation

Goth

CI

Google + Auth = Goth

A simple library to generate and retrieve OAuth2 tokens for use with Google Cloud Service accounts.

Installation

Note: below are instructions for using Goth v1.3+. For more information on earlier versions of Goth, see v1.2.0 documentation on hexdocs.pm.

  1. Add :goth to your list of dependencies in mix.exs.

    defdepsdo[{:goth,"~> 1.4"}]end
  2. Add Goth to your supervision tree:

    defmoduleMyApp.ApplicationdouseApplicationdefstart(_type,_args)docredentials="GOOGLE_APPLICATION_CREDENTIALS_JSON"|>System.fetch_env!()|>Jason.decode!()source={:service_account,credentials}children=[{Goth,name: MyApp.Goth,source: source}]Supervisor.start_link(children,strategy: :one_for_one)endend

    If you set GOOGLE_APPLICATION_CREDENTIALS or GOOGLE_APPLICATION_CREDENTIALS_JSON, have a ~/.config/gcloud/application_default_credentials.json file, ~/.config/gcloud/configurations/config_default file or deploy your application to Google Cloud, you can omit the :source option:

    defstart(_type,_args)dochildren=[{Goth,name: MyApp.Goth}]Supervisor.start_link(children,strategy: :one_for_one)end

    If you want to use multiple credentials, you may consider doing:

    defstart(_type,_args)doSupervisor.start_link(servers(),strategy: :one_for_one)enddefpserversdoservers=[{MyApp.Cred1,source1},...{MyApp.CredN,source2}]for{name,source}<-serversdoSupervisor.child_spec({Goth,name: name,source: source},id: name)endend
  3. Fetch the token:

    iex>Goth.fetch!(MyApp.Goth)%Goth.Token{expires: 1453356568,token: "ya29.cALlJ4ICWRvMkYB-WsAR-CZnExE459PA7QPqKg5nei9y2T9-iqmbcgxq8XrTATNn_BPim",type: "Bearer",
    ...
    }

See Goth.start_link/1 for more information about possible configuration options.

Upgrading from Goth 1.2

See Upgrading from Goth 1.2 guide for more information.

Community resources

Copyright and License

Copyright (c) 2016 Phil Burrows

This work is free. You can redistribute it and/or modify it under the terms of the MIT License. See the LICENSE.md file for more details.

About

Elixir package for Oauth authentication via Google Cloud APIs

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages