Current section
3 Versions
Jump to
Current section
3 Versions
Compare versions
4
files changed
+23
additions
-11
deletions
| @@ -1,5 +1,14 @@ | |
| 1 1 | # Überauth Weibo |
| 2 2 | |
| 3 | + [![Build Status][travis-img]][travis] [![Hex Version][hex-img]][hex] [![License][license-img]][license] |
| 4 | + |
| 5 | + [travis-img]: https://travis-ci.org/he9qi/ueberauth_weibo.png?branch=master |
| 6 | + [travis]: https://travis-ci.org/he9qi/ueberauth_weibo |
| 7 | + [hex-img]: https://img.shields.io/hexpm/v/ueberauth_weibo.svg |
| 8 | + [hex]: https://hex.pm/packages/ueberauth_weibo |
| 9 | + [license-img]: http://img.shields.io/badge/license-MIT-brightgreen.svg |
| 10 | + [license]: http://opensource.org/licenses/MIT |
| 11 | + |
| 3 12 | > Weibo OAuth2 strategy for Überauth. |
| 4 13 | |
| 5 14 | ## Installation |
| @@ -20,4 +20,4 @@ | |
| 20 20 | [{<<"app">>,<<"ueberauth">>}, |
| 21 21 | {<<"optional">>,false}, |
| 22 22 | {<<"requirement">>,<<"~> 0.2">>}]}]}. |
| 23 | - {<<"version">>,<<"0.0.1">>}. |
| 23 | + {<<"version">>,<<"0.0.2">>}. |
| @@ -43,10 +43,9 @@ defmodule Ueberauth.Strategy.Weibo.OAuth do | |
| 43 43 | end |
| 44 44 | |
| 45 45 | @doc """ |
| 46 | - Calls OAuth2 Client to get access token. Since weibo returns body as string: |
| 47 | - :body=>"{\"access_token\":\"2.xxx\",\"expires_in\":86400,\"uid\":\"12345\"}", |
| 48 | - request does not parse correctly. As a result, a temp fix is to build a new |
| 49 | - access token using decoded dict. |
| 46 | + Calls OAuth2 Client to get access token. Weibo requires Content-Type header as 'x-www-form-urlencoded' |
| 47 | + while returns body as JSON string: :body=>"{\"access_token\":\"2.xxx\",\"expires_in\":86400,\"uid\":\"12345\"}". |
| 48 | + As a result, response cannot not be parsed correctly. A temp fix is to build a new access token using decoded dict. |
| 50 49 | """ |
| 51 50 | def get_token!(params \\ [], options \\ %{}) do |
| 52 51 | headers = Dict.get(options, :headers, []) |
| @@ -57,12 +56,18 @@ defmodule Ueberauth.Strategy.Weibo.OAuth do | |
| 57 56 | |> client |
| 58 57 | |> OAuth2.Client.get_token!(params, headers, options) |
| 59 58 | |
| 59 | + token |
| 60 | + |> get_access_token(token.access_token) |
| 61 | + end |
| 62 | + |
| 63 | + def get_access_token(token, nil) do |
| 60 64 | token.other_params |
| 61 65 | |> Map.keys |
| 62 66 | |> List.first |
| 63 67 | |> Poison.decode! |
| 64 68 | |> OAuth2.AccessToken.new(token.client) |
| 65 69 | end |
| 70 | + def get_access_token(token, _), do: token |
| 66 71 | |
| 67 72 | # Strategy Callbacks |
| @@ -1,7 +1,7 @@ | |
| 1 1 | defmodule UeberauthWeibo.Mixfile do |
| 2 2 | use Mix.Project |
| 3 3 | |
| 4 | - @version "0.0.1" |
| 4 | + @version "0.0.2" |
| 5 5 | |
| 6 6 | def project do |
| 7 7 | [app: :ueberauth_weibo, |
| @@ -28,17 +28,15 @@ defmodule UeberauthWeibo.Mixfile do | |
| 28 28 | [{:ueberauth, "~> 0.2"}, |
| 29 29 | {:oauth2, "~> 0.5"}, |
| 30 30 | |
| 31 | + {:exvcr, "~> 0.7", only: :test}, |
| 32 | + |
| 31 33 | # docs dependencies |
| 32 34 | {:earmark, "~>0.1", only: :dev}, |
| 33 35 | {:ex_doc, "~>0.1", only: :dev}] |
| 34 36 | end |
| 35 37 | |
| 36 38 | defp docs do |
| 37 | - [extras: docs_extras, main: "extra-readme"] |
| 38 | - end |
| 39 | - |
| 40 | - defp docs_extras do |
| 41 | - ["README.md"] |
| 39 | + [extras: ["README.md"], main: "readme"] |
| 42 40 | end |
| 43 41 | |
| 44 42 | defp description do |