Skip to content

Commit

Permalink
and the rename is complete. That was easy enough.
Browse files Browse the repository at this point in the history
  • Loading branch information
peburrows committed Jan 21, 2016
1 parent 8c13fb2 commit 3a719fd
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 45 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# GoogleAuth
# Goth
Google + Auth = Goth

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

Expand All @@ -7,20 +8,20 @@ A simple library to generate and retrieve Oauth2 tokens for use with Google Clou
1. Add google_auth to your list of dependencies in `mix.exs`:
```elixir
def deps do
[{:google_auth, "~> 0.0.1"}]
[{:goth, "~> 0.0.1"}]
end
```

2. Ensure google_auth is started before your application:
```elixir
def application do
[applications: [:google_auth]]
[applications: [:goth]]
end
```

3. Pass in your credentials json downloaded from your GCE account:
```elixir
config :google_auth,
config :goth,
json: "path/to/google/json/creds.json" |> File.read!
```

Expand All @@ -29,10 +30,10 @@ A simple library to generate and retrieve Oauth2 tokens for use with Google Clou
### Retrieve a token:
Call `Token.for_scope/1` passing in a string of scopes, separated by a comma:
```elixir
alias GoogleAuth.Token
alias Goth.Token
{:ok, token} = Token.for_scope("https://www.googleapis.com/auth/pubsub")
#=>
%GoogleAuth.Token{
%Goth.Token{
expires: 1453356568,
token: "ya29.cALlJ4ICWRvMkYB-WsAR-CZnExE459PA7QPqKg5nei9y2T9-iqmbcgxq8XrTATNn_BPim",
type: "Bearer"
Expand Down
4 changes: 2 additions & 2 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ use Mix.Config

# You can configure for your application as:
#
# config :google_auth, key: :value
# config :goth, key: :value
#
# And access this configuration in your application as:
#
# Application.get_env(:google_auth, :key)
# Application.get_env(:goth, :key)
#
# Or configure a 3rd-party app:
#
Expand Down
2 changes: 1 addition & 1 deletion config/dev.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config

config :google_auth,
config :goth,
json: "config/dev-credentials.json" |> Path.expand |> File.read!
2 changes: 1 addition & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config

config :google_auth,
config :goth,
json: "config/test-credentials.json" |> Path.expand |> File.read!
4 changes: 2 additions & 2 deletions lib/goth.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
defmodule GoogleAuth do
defmodule Goth do
use Application

# for now, just spin up the supervisor
def start(_type, _args) do
GoogleAuth.Supervisor.start_link
Goth.Supervisor.start_link
end
end
8 changes: 4 additions & 4 deletions lib/goth/client.ex
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
defmodule GoogleAuth.Client do
alias GoogleAuth.Config
alias GoogleAuth.Token
defmodule Goth.Client do
alias Goth.Config
alias Goth.Token

def get_access_token(scope) do
endpoint = Application.get_env(:google_auth, :endpoint, "https://www.googleapis.com")
endpoint = Application.get_env(:goth, :endpoint, "https://www.googleapis.com")

{:ok, response} = HTTPoison.post( Path.join([endpoint, "/oauth2/v4/token"]),
{:form, [grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
Expand Down
6 changes: 3 additions & 3 deletions lib/goth/config.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
defmodule GoogleAuth.Config do
defmodule Goth.Config do
use GenServer

@json Application.get_env(:google_auth, :json)
@config Application.get_env(:google_auth, :config, %{})
@json Application.get_env(:goth, :json)
@config Application.get_env(:goth, :config, %{})

def start_link do
GenServer.start_link(__MODULE__, :ok, [name: __MODULE__])
Expand Down
6 changes: 3 additions & 3 deletions lib/goth/supervisor.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule GoogleAuth.Supervisor do
defmodule Goth.Supervisor do
use Supervisor
alias GoogleAuth.Config
alias GoogleAuth.TokenStore
alias Goth.Config
alias Goth.TokenStore

def start_link do
Supervisor.start_link(__MODULE__, :ok, name: __MODULE__)
Expand Down
6 changes: 3 additions & 3 deletions lib/goth/token.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule GoogleAuth.Token do
alias GoogleAuth.TokenStore
alias GoogleAuth.Client
defmodule Goth.Token do
alias Goth.TokenStore
alias Goth.Client

defstruct [:token, :type, :expires]

Expand Down
4 changes: 2 additions & 2 deletions lib/goth/token_store.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule GoogleAuth.TokenStore do
defmodule Goth.TokenStore do
use GenServer
alias GoogleAuth.Token
alias Goth.Token

def start_link do
GenServer.start_link(__MODULE__, %{}, [name: __MODULE__])
Expand Down
6 changes: 3 additions & 3 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
defmodule GoogleAuth.Mixfile do
defmodule Goth.Mixfile do
use Mix.Project

def project do
[app: :google_auth,
[app: :goth,
version: "0.0.1",
elixir: "~> 1.2",
build_embedded: Mix.env == :prod,
Expand All @@ -15,7 +15,7 @@ defmodule GoogleAuth.Mixfile do
# Type "mix help compile.app" for more information
def application do
[
mod: {GoogleAuth, []},
mod: {Goth, []},
applications: [:logger, :httpoison]
]
end
Expand Down
10 changes: 5 additions & 5 deletions test/goth/client_test.exs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
defmodule GoogleAuth.ClientTest do
defmodule Goth.ClientTest do
use ExUnit.Case
alias GoogleAuth.Client
alias GoogleAuth.Token
alias Goth.Client
alias Goth.Token

setup do
bypass = Bypass.open
Application.put_env(:google_auth, :endpoint, "http://localhost:#{bypass.port}")
Application.put_env(:goth, :endpoint, "http://localhost:#{bypass.port}")
{:ok, bypass: bypass}
end

test "we include all necessary attributes in the JWT" do
{:ok, email} = GoogleAuth.Config.get(:client_email)
{:ok, email} = Goth.Config.get(:client_email)
iat = :os.system_time(:seconds)
exp = iat+10
scope = "prediction"
Expand Down
4 changes: 2 additions & 2 deletions test/goth/config_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule GoogleAuth.ConfigTest do
defmodule Goth.ConfigTest do
use ExUnit.Case
alias GoogleAuth.Config
alias Goth.Config

test "setting and retrieving value" do
Config.set(:key, "123")
Expand Down
6 changes: 3 additions & 3 deletions test/goth/token_store_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule GoogleAuth.TokenStoreTest do
defmodule Goth.TokenStoreTest do
use ExUnit.Case
alias GoogleAuth.TokenStore
alias GoogleAuth.Token
alias Goth.TokenStore
alias Goth.Token

test "we can store an access token" do
TokenStore.store("devstorage.readonly, prediction", %Token{token: "123", type: "Bearer", expires: 100})
Expand Down
6 changes: 3 additions & 3 deletions test/goth/token_test.exs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
defmodule GoogleAuth.TokenTest do
defmodule Goth.TokenTest do
use ExUnit.Case
alias GoogleAuth.Token
alias Goth.Token

setup do
bypass = Bypass.open
Application.put_env(:google_auth, :endpoint, "http://localhost:#{bypass.port}")
Application.put_env(:goth, :endpoint, "http://localhost:#{bypass.port}")
{:ok, bypass: bypass}
end

Expand Down
4 changes: 2 additions & 2 deletions test/goth_test.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule GoogleAuthTest do
defmodule GothTest do
use ExUnit.Case
doctest GoogleAuth
doctest Goth
end

0 comments on commit 3a719fd

Please sign in to comment.