Current section
19 Versions
Jump to
Current section
19 Versions
Compare versions
5
files changed
+30
additions
-21
deletions
| @@ -12,12 +12,12 @@ | |
| 12 12 | {<<"maintainers">>,[<<"Sean Callan">>]}. |
| 13 13 | {<<"name">>,<<"ueberauth_google">>}. |
| 14 14 | {<<"requirements">>, |
| 15 | - [[{<<"app">>,<<"ueberauth">>}, |
| 16 | - {<<"name">>,<<"ueberauth">>}, |
| 17 | - {<<"optional">>,false}, |
| 18 | - {<<"requirement">>,<<"~> 0.4">>}], |
| 19 | - [{<<"app">>,<<"oauth2">>}, |
| 15 | + [[{<<"app">>,<<"oauth2">>}, |
| 20 16 | {<<"name">>,<<"oauth2">>}, |
| 21 17 | {<<"optional">>,false}, |
| 22 | - {<<"requirement">>,<<"~> 0.8">>}]]}. |
| 23 | - {<<"version">>,<<"0.5.0">>}. |
| 18 | + {<<"requirement">>,<<"~> 0.9">>}], |
| 19 | + [{<<"app">>,<<"ueberauth">>}, |
| 20 | + {<<"name">>,<<"ueberauth">>}, |
| 21 | + {<<"optional">>,false}, |
| 22 | + {<<"requirement">>,<<"~> 0.4">>}]]}. |
| 23 | + {<<"version">>,<<"0.6.0">>}. |
| @@ -16,10 +16,12 @@ defmodule Ueberauth.Strategy.Google do | |
| 16 16 | scopes = conn.params["scope"] || option(conn, :default_scope) |
| 17 17 | |
| 18 18 | opts = |
| 19 | - [ scope: scopes ] |
| 19 | + [scope: scopes] |
| 20 20 | |> with_optional(:hd, conn) |
| 21 21 | |> with_optional(:approval_prompt, conn) |
| 22 22 | |> with_optional(:access_type, conn) |
| 23 | + |> with_param(:access_type, conn) |
| 24 | + |> with_param(:prompt, conn) |
| 23 25 | |> with_param(:state, conn) |
| 24 26 | |> Keyword.put(:redirect_uri, callback_url(conn)) |
| 25 27 | |
| @@ -29,7 +31,7 @@ defmodule Ueberauth.Strategy.Google do | |
| 29 31 | @doc """ |
| 30 32 | Handles the callback from Google. |
| 31 33 | """ |
| 32 | - def handle_callback!(%Plug.Conn{ params: %{ "code" => code } } = conn) do |
| 34 | + def handle_callback!(%Plug.Conn{params: %{"code" => code}} = conn) do |
| 33 35 | opts = [redirect_uri: callback_url(conn)] |
| 34 36 | token = Ueberauth.Strategy.Google.OAuth.get_token!([code: code], opts) |
| 35 37 | |
| @@ -68,14 +70,15 @@ defmodule Ueberauth.Strategy.Google do | |
| 68 70 | Includes the credentials from the google response. |
| 69 71 | """ |
| 70 72 | def credentials(conn) do |
| 71 | - token = conn.private.google_token |
| 72 | - scopes = (token.other_params["scope"] || "") |
| 73 | - |> String.split(",") |
| 73 | + token = conn.private.google_token |
| 74 | + scope_string = (token.other_params["scope"] || "") |
| 75 | + scopes = String.split(scope_string, ",") |
| 74 76 | |
| 75 77 | %Credentials{ |
| 76 78 | expires: !!token.expires_at, |
| 77 79 | expires_at: token.expires_at, |
| 78 80 | scopes: scopes, |
| 81 | + token_type: Map.get(token, :token_type), |
| 79 82 | refresh_token: token.refresh_token, |
| 80 83 | token: token.access_token |
| 81 84 | } |
| @@ -121,11 +124,11 @@ defmodule Ueberauth.Strategy.Google do | |
| 121 124 | resp = Ueberauth.Strategy.Google.OAuth.get(token, path) |
| 122 125 | |
| 123 126 | case resp do |
| 124 | - { :ok, %OAuth2.Response{status_code: 401, body: _body}} -> |
| 127 | + {:ok, %OAuth2.Response{status_code: 401, body: _body}} -> |
| 125 128 | set_errors!(conn, [error("token", "unauthorized")]) |
| 126 | - { :ok, %OAuth2.Response{status_code: status_code, body: user} } when status_code in 200..399 -> |
| 129 | + {:ok, %OAuth2.Response{status_code: status_code, body: user}} when status_code in 200..399 -> |
| 127 130 | put_private(conn, :google_user, user) |
| 128 | - { :error, %OAuth2.Error{reason: reason} } -> |
| 131 | + {:error, %OAuth2.Error{reason: reason}} -> |
| 129 132 | set_errors!(conn, [error("OAuth2", reason)]) |
| 130 133 | end |
| 131 134 | end |
| @@ -139,6 +142,6 @@ defmodule Ueberauth.Strategy.Google do | |
| 139 142 | end |
| 140 143 | |
| 141 144 | defp option(conn, key) do |
| 142 | - Dict.get(options(conn), key, Dict.get(default_options(), key)) |
| 145 | + Keyword.get(options(conn), key, Keyword.get(default_options(), key)) |
| 143 146 | end |
| 144 147 | end |
| @@ -45,7 +45,8 @@ defmodule Ueberauth.Strategy.Google.OAuth do | |
| 45 45 | end |
| 46 46 | |
| 47 47 | def get(token, url, headers \\ [], opts \\ []) do |
| 48 | - client([token: token]) |
| 48 | + [token: token] |
| 49 | + |> client |
| 49 50 | |> put_param("client_secret", client().client_secret) |
| 50 51 | |> OAuth2.Client.get(url, headers, opts) |
| 51 52 | end |
| @@ -1,2 +1,3 @@ | |
| 1 1 | defmodule UeberauthGoogle do |
| 2 | + @moduledoc false |
| 2 3 | end |
| @@ -1,7 +1,7 @@ | |
| 1 1 | defmodule UeberauthGoogle.Mixfile do |
| 2 2 | use Mix.Project |
| 3 3 | |
| 4 | - @version "0.5.0" |
| 4 | + @version "0.6.0" |
| 5 5 | @url "https://github.com/ueberauth/ueberauth_google" |
| 6 6 | |
| 7 7 | def project do |
| @@ -24,10 +24,14 @@ defmodule UeberauthGoogle.Mixfile do | |
| 24 24 | end |
| 25 25 | |
| 26 26 | defp deps do |
| 27 | - [{:ueberauth, "~> 0.4"}, |
| 28 | - {:oauth2, "~> 0.8"}, |
| 27 | + [ |
| 28 | + {:oauth2, "~> 0.9"}, |
| 29 | + {:ueberauth, "~> 0.4"}, |
| 30 | + |
| 31 | + {:credo, "~> 0.8", only: [:dev, :test]}, |
| 32 | + {:earmark, ">= 0.0.0", only: :dev}, |
| 29 33 | {:ex_doc, "~> 0.3", only: :dev}, |
| 30 | - {:earmark, ">= 0.0.0", only: :dev}] |
| 34 | + ] |
| 31 35 | end |
| 32 36 | |
| 33 37 | defp docs do |