Initial commit
This commit is contained in:
parent
620f476fb8
commit
9906f47bc3
5
.idea/codeStyles/codeStyleConfig.xml
Normal file
5
.idea/codeStyles/codeStyleConfig.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<state>
|
||||||
|
<option name="PREFERRED_PROJECT_CODE_STYLE" value="mastodon" />
|
||||||
|
</state>
|
||||||
|
</component>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/ueberauth_twitter.iml" filepath="$PROJECT_DIR$/.idea/ueberauth_twitter.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
8
.idea/ueberauth_twitter.iml
Normal file
8
.idea/ueberauth_twitter.iml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="WEB_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
13
.idea/workspace.xml
Normal file
13
.idea/workspace.xml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectViewState">
|
||||||
|
<option name="autoscrollFromSource" value="true" />
|
||||||
|
<option name="autoscrollToSource" value="true" />
|
||||||
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
|
<option name="showLibraryContents" value="true" />
|
||||||
|
</component>
|
||||||
|
<component name="PropertiesComponent">
|
||||||
|
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
|
||||||
|
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
|
||||||
|
</component>
|
||||||
|
</project>
|
28
README.md
28
README.md
@ -1,38 +1,38 @@
|
|||||||
# Überauth Twitter
|
# Überauth OpenStreetMap
|
||||||
|
|
||||||
> Twitter strategy for Überauth.
|
> OpenStreetMap strategy for Überauth.
|
||||||
|
|
||||||
_Note_: Sessions are required for this strategy.
|
_Note_: Sessions are required for this strategy.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
1. Setup your application at [Twitter Developers](https://dev.twitter.com/).
|
1. Setup your application at [OpenStreetMap Developers](https://dev.OpenStreetMap.com/).
|
||||||
|
|
||||||
1. Add `:ueberauth_twitter` to your list of dependencies in `mix.exs`:
|
1. Add `:ueberauth_OpenStreetMap` to your list of dependencies in `mix.exs`:
|
||||||
|
|
||||||
```elixir
|
```elixir
|
||||||
def deps do
|
def deps do
|
||||||
[
|
[
|
||||||
{:ueberauth_twitter, "~> 0.3"}
|
{:ueberauth_OpenStreetMap, "~> 0.3"}
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Add Twitter to your Überauth configuration:
|
1. Add OpenStreetMap to your Überauth configuration:
|
||||||
|
|
||||||
```elixir
|
```elixir
|
||||||
config :ueberauth, Ueberauth,
|
config :ueberauth, Ueberauth,
|
||||||
providers: [
|
providers: [
|
||||||
twitter: {Ueberauth.Strategy.Twitter, []}
|
OpenStreetMap: {Ueberauth.Strategy.OpenStreetMap, []}
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Update your provider configuration:
|
1. Update your provider configuration:
|
||||||
|
|
||||||
```elixir
|
```elixir
|
||||||
config :ueberauth, Ueberauth.Strategy.Twitter.OAuth,
|
config :ueberauth, Ueberauth.Strategy.OpenStreetMap.OAuth,
|
||||||
consumer_key: System.get_env("TWITTER_CONSUMER_KEY"),
|
consumer_key: System.get_env("OpenStreetMap_CONSUMER_KEY"),
|
||||||
consumer_secret: System.get_env("TWITTER_CONSUMER_SECRET")
|
consumer_secret: System.get_env("OpenStreetMap_CONSUMER_SECRET")
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Include the Überauth plug in your controller:
|
1. Include the Überauth plug in your controller:
|
||||||
@ -64,16 +64,16 @@ For an example implementation see the [Überauth Example](https://github.com/ueb
|
|||||||
|
|
||||||
Depending on the configured url you can initiate the request through:
|
Depending on the configured url you can initiate the request through:
|
||||||
|
|
||||||
/auth/twitter
|
/auth/OpenStreetMap
|
||||||
|
|
||||||
## Development mode
|
## Development mode
|
||||||
|
|
||||||
As noted when registering your application on the Twitter Developer site, you need to explicitly specify the `oauth_callback` url. While in development, this is an example url you need to enter.
|
As noted when registering your application on the OpenStreetMap Developer site, you need to explicitly specify the `oauth_callback` url. While in development, this is an example url you need to enter.
|
||||||
|
|
||||||
Website - http://127.0.0.1
|
Website - http://127.0.0.1
|
||||||
Callback URL - http://127.0.0.1:4000/auth/twitter/callback
|
Callback URL - http://127.0.0.1:4000/auth/OpenStreetMap/callback
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
Please see [LICENSE](https://github.com/ueberauth/ueberauth_twitter/blob/master/LICENSE) for licensing details.
|
Please see [LICENSE](https://github.com/ueberauth/ueberauth_OpenStreetMap/blob/master/LICENSE) for licensing details.
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
defmodule Ueberauth.Strategy.Twitter do
|
defmodule Ueberauth.Strategy.OpenStreetMap do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Twitter Strategy for Überauth.
|
Opestreetmap Strategy for Überauth.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
use Ueberauth.Strategy, uid_field: :id_str
|
use Ueberauth.Strategy, uid_field: :id_str
|
||||||
@ -8,25 +8,25 @@ defmodule Ueberauth.Strategy.Twitter do
|
|||||||
alias Ueberauth.Auth.Info
|
alias Ueberauth.Auth.Info
|
||||||
alias Ueberauth.Auth.Credentials
|
alias Ueberauth.Auth.Credentials
|
||||||
alias Ueberauth.Auth.Extra
|
alias Ueberauth.Auth.Extra
|
||||||
alias Ueberauth.Strategy.Twitter
|
alias Ueberauth.Strategy.OpenStreetMap
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Handles initial request for Twitter authentication.
|
Handles initial request for OpenStreetMap authentication.
|
||||||
"""
|
"""
|
||||||
def handle_request!(conn) do
|
def handle_request!(conn) do
|
||||||
token = Twitter.OAuth.request_token!([], [redirect_uri: callback_url(conn)])
|
token = OpenStreetMap.OAuth.request_token!([], [redirect_uri: callback_url(conn)])
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_session(:twitter_token, token)
|
|> put_session(:OpenStreetMap_token, token)
|
||||||
|> redirect!(Twitter.OAuth.authorize_url!(token))
|
|> redirect!(OpenStreetMap.OAuth.authorize_url!(token))
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Handles the callback from Twitter.
|
Handles the callback from OpenStreetMap.
|
||||||
"""
|
"""
|
||||||
def handle_callback!(%Plug.Conn{params: %{"oauth_verifier" => oauth_verifier}} = conn) do
|
def handle_callback!(%Plug.Conn{params: %{"oauth_verifier" => oauth_verifier}} = conn) do
|
||||||
token = get_session(conn, :twitter_token)
|
token = get_session(conn, :OpenStreetMap_token)
|
||||||
case Twitter.OAuth.access_token(token, oauth_verifier) do
|
case OpenStreetMap.OAuth.access_token(token, oauth_verifier) do
|
||||||
{:ok, access_token} -> fetch_user(conn, access_token)
|
{:ok, access_token} -> fetch_user(conn, access_token)
|
||||||
{:error, error} -> set_errors!(conn, [error(error.code, error.reason)])
|
{:error, error} -> set_errors!(conn, [error(error.code, error.reason)])
|
||||||
end
|
end
|
||||||
@ -40,8 +40,8 @@ defmodule Ueberauth.Strategy.Twitter do
|
|||||||
@doc false
|
@doc false
|
||||||
def handle_cleanup!(conn) do
|
def handle_cleanup!(conn) do
|
||||||
conn
|
conn
|
||||||
|> put_private(:twitter_user, nil)
|
|> put_private(:OpenStreetMap_user, nil)
|
||||||
|> put_session(:twitter_token, nil)
|
|> put_session(:OpenStreetMap_token, nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
@ -53,14 +53,14 @@ defmodule Ueberauth.Strategy.Twitter do
|
|||||||
|> option(:uid_field)
|
|> option(:uid_field)
|
||||||
|> to_string
|
|> to_string
|
||||||
|
|
||||||
conn.private.twitter_user[uid_field]
|
conn.private.OpenStreetMap_user[uid_field]
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Includes the credentials from the twitter response.
|
Includes the credentials from the OpenStreetMap response.
|
||||||
"""
|
"""
|
||||||
def credentials(conn) do
|
def credentials(conn) do
|
||||||
{token, secret} = conn.private.twitter_token
|
{token, secret} = conn.private.OpenStreetMap_token
|
||||||
|
|
||||||
%Credentials{token: token, secret: secret}
|
%Credentials{token: token, secret: secret}
|
||||||
end
|
end
|
||||||
@ -69,7 +69,7 @@ defmodule Ueberauth.Strategy.Twitter do
|
|||||||
Fetches the fields to populate the info section of the `Ueberauth.Auth` struct.
|
Fetches the fields to populate the info section of the `Ueberauth.Auth` struct.
|
||||||
"""
|
"""
|
||||||
def info(conn) do
|
def info(conn) do
|
||||||
user = conn.private.twitter_user
|
user = conn.private.OpenStreetMap_user
|
||||||
|
|
||||||
%Info{
|
%Info{
|
||||||
email: user["email"],
|
email: user["email"],
|
||||||
@ -79,22 +79,22 @@ defmodule Ueberauth.Strategy.Twitter do
|
|||||||
description: user["description"],
|
description: user["description"],
|
||||||
location: user["location"],
|
location: user["location"],
|
||||||
urls: %{
|
urls: %{
|
||||||
Twitter: "https://twitter.com/#{user["screen_name"]}",
|
OpenStreetMap: "https://OpenStreetMap.com/#{user["screen_name"]}",
|
||||||
Website: user["url"]
|
Website: user["url"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Stores the raw information (including the token) obtained from the twitter callback.
|
Stores the raw information (including the token) obtained from the OpenStreetMap callback.
|
||||||
"""
|
"""
|
||||||
def extra(conn) do
|
def extra(conn) do
|
||||||
{token, _secret} = get_session(conn, :twitter_token)
|
{token, _secret} = get_session(conn, :OpenStreetMap_token)
|
||||||
|
|
||||||
%Extra{
|
%Extra{
|
||||||
raw_info: %{
|
raw_info: %{
|
||||||
token: token,
|
token: token,
|
||||||
user: conn.private.twitter_user
|
user: conn.private.OpenStreetMap_user
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@ -102,14 +102,14 @@ defmodule Ueberauth.Strategy.Twitter do
|
|||||||
defp fetch_user(conn, token) do
|
defp fetch_user(conn, token) do
|
||||||
params = [{"include_entities", false}, {"skip_status", true}, {"include_email", true}]
|
params = [{"include_entities", false}, {"skip_status", true}, {"include_email", true}]
|
||||||
|
|
||||||
case Twitter.OAuth.get("/1.1/account/verify_credentials.json", params, token) do
|
case OpenStreetMap.OAuth.get("/1.1/account/verify_credentials.json", params, token) do
|
||||||
{:ok, %{status_code: 401, body: _, headers: _}} ->
|
{:ok, %{status_code: 401, body: _, headers: _}} ->
|
||||||
set_errors!(conn, [error("token", "unauthorized")])
|
set_errors!(conn, [error("token", "unauthorized")])
|
||||||
|
|
||||||
{:ok, %{status_code: status_code, body: body, headers: _}} when status_code in 200..399 ->
|
{:ok, %{status_code: status_code, body: body, headers: _}} when status_code in 200..399 ->
|
||||||
conn
|
conn
|
||||||
|> put_private(:twitter_token, token)
|
|> put_private(:OpenStreetMap_token, token)
|
||||||
|> put_private(:twitter_user, body)
|
|> put_private(:OpenStreetMap_user, body)
|
||||||
|
|
||||||
{:ok, %{status_code: _, body: body, headers: _}} ->
|
{:ok, %{status_code: _, body: body, headers: _}} ->
|
||||||
error = List.first(body["errors"])
|
error = List.first(body["errors"])
|
@ -1,4 +1,4 @@
|
|||||||
defmodule Ueberauth.Strategy.Twitter.OAuth.Internal do
|
defmodule Ueberauth.Strategy.OpenStreetMap.OAuth.Internal do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
A layer to handle OAuth signing, etc.
|
A layer to handle OAuth signing, etc.
|
||||||
"""
|
"""
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
defmodule Ueberauth.Strategy.Twitter.OAuth do
|
defmodule Ueberauth.Strategy.OpenStreetMap.OAuth do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
OAuth1 for Twitter.
|
OAuth1 for OpenStreetMap.
|
||||||
|
|
||||||
Add `consumer_key` and `consumer_secret` to your configuration:
|
Add `consumer_key` and `consumer_secret` to your configuration:
|
||||||
|
|
||||||
config :ueberauth, Ueberauth.Strategy.Twitter.OAuth,
|
config :ueberauth, Ueberauth.Strategy.OpenStreetMap.OAuth,
|
||||||
consumer_key: System.get_env("TWITTER_CONSUMER_KEY"),
|
consumer_key: System.get_env("OpenStreetMap_CONSUMER_KEY"),
|
||||||
consumer_secret: System.get_env("TWITTER_CONSUMER_SECRET"),
|
consumer_secret: System.get_env("OpenStreetMap_CONSUMER_SECRET"),
|
||||||
redirect_uri: System.get_env("TWITTER_REDIRECT_URI")
|
redirect_uri: System.get_env("OpenStreetMap_REDIRECT_URI")
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias Ueberauth.Strategy.Twitter.OAuth.Internal
|
alias Ueberauth.Strategy.OpenStreetMap.OAuth.Internal
|
||||||
|
|
||||||
@defaults [access_token: "/oauth/access_token",
|
@defaults [access_token: "/oauth/access_token",
|
||||||
authorize_url: "/oauth/authorize",
|
authorize_url: "/oauth/authorize",
|
||||||
request_token: "/oauth/request_token",
|
request_token: "/oauth/request_token",
|
||||||
site: "https://api.twitter.com"]
|
site: "https://api.OpenStreetMap.com"]
|
||||||
|
|
||||||
defmodule ApiError do
|
defmodule ApiError do
|
||||||
@moduledoc "Raised on OAuth API errors."
|
@moduledoc "Raised on OAuth API errors."
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
defmodule UeberauthTwitter do
|
defmodule UeberauthOpenStreetMap do
|
||||||
@moduledoc false
|
@moduledoc false
|
||||||
end
|
end
|
||||||
|
10
mix.exs
10
mix.exs
@ -1,13 +1,13 @@
|
|||||||
defmodule UeberauthTwitter.Mixfile do
|
defmodule UeberauthOpenStreetMap.Mixfile do
|
||||||
use Mix.Project
|
use Mix.Project
|
||||||
|
|
||||||
@version "0.3.0"
|
@version "0.3.0"
|
||||||
@url "https://github.com/ueberauth/ueberauth_twitter"
|
@url "https://github.com/ueberauth/ueberauth_OpenStreetMap"
|
||||||
|
|
||||||
def project do
|
def project do
|
||||||
[app: :ueberauth_twitter,
|
[app: :ueberauth_OpenStreetMap,
|
||||||
version: @version,
|
version: @version,
|
||||||
name: "Ueberauth Twitter Strategy",
|
name: "Ueberauth OpenStreetMap Strategy",
|
||||||
package: package(),
|
package: package(),
|
||||||
elixir: "~> 1.1",
|
elixir: "~> 1.1",
|
||||||
build_embedded: Mix.env == :prod,
|
build_embedded: Mix.env == :prod,
|
||||||
@ -45,7 +45,7 @@ defmodule UeberauthTwitter.Mixfile do
|
|||||||
end
|
end
|
||||||
|
|
||||||
defp description do
|
defp description do
|
||||||
"An Uberauth strategy for Twitter authentication."
|
"An Uberauth strategy for OpenStreetMap authentication."
|
||||||
end
|
end
|
||||||
|
|
||||||
defp package do
|
defp package do
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
defmodule Ueberauth.Strategy.Twitter.OAuthTest do
|
defmodule Ueberauth.Strategy.OpenStreetMap.OAuthTest do
|
||||||
use ExUnit.Case, async: true
|
use ExUnit.Case, async: true
|
||||||
|
|
||||||
alias Ueberauth.Strategy.Twitter.OAuth
|
alias Ueberauth.Strategy.OpenStreetMap.OAuth
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
Application.put_env :ueberauth, OAuth,
|
Application.put_env :ueberauth, OAuth,
|
||||||
@ -18,7 +18,7 @@ defmodule Ueberauth.Strategy.Twitter.OAuthTest do
|
|||||||
|
|
||||||
test "access_token!/2 raises an appropriate error on network failure" do
|
test "access_token!/2 raises an appropriate error on network failure" do
|
||||||
assert_raise RuntimeError, ~r/nxdomain/i, fn ->
|
assert_raise RuntimeError, ~r/nxdomain/i, fn ->
|
||||||
OAuth.access_token! {"token", "secret"}, "verifier", site: "https://bogusapi.twitter.com"
|
OAuth.access_token! {"token", "secret"}, "verifier", site: "https://bogusapi.OpenStreetMap.com"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ defmodule Ueberauth.Strategy.Twitter.OAuthTest do
|
|||||||
|
|
||||||
test "request_token!/2: raises an appropriate error on network failure" do
|
test "request_token!/2: raises an appropriate error on network failure" do
|
||||||
assert_raise RuntimeError, ~r/nxdomain/i, fn ->
|
assert_raise RuntimeError, ~r/nxdomain/i, fn ->
|
||||||
OAuth.request_token! [], site: "https://bogusapi.twitter.com", redirect_uri: "some/uri"
|
OAuth.request_token! [], site: "https://bogusapi.OpenStreetMap.com", redirect_uri: "some/uri"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
defmodule UeberauthTwitterTest do
|
defmodule UeberauthOpenStreetMapTest do
|
||||||
use ExUnit.Case
|
use ExUnit.Case
|
||||||
doctest UeberauthTwitter
|
doctest UeberauthOpenStreetMap
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user