-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
swap out openstreetmap oauth1 to use new oauth2.0 refs #277
- Loading branch information
Showing
8 changed files
with
73 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,8 @@ defaults: &defaults | |
reply_to: "[email protected]" | ||
omniauth_osm_key: "ABC" | ||
omniauth_osm_secret: "ABC" | ||
omniauth_osm_oauth2_key: "ABC" | ||
omniauth_osm_oauth2_secret: "ABC" | ||
omniauth_twitter_key: "ABC" | ||
omniauth_twitter_secret: "ABC" | ||
omniauth_mediawiki_site: "https://commons.wikimedia.org" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
require 'omniauth-oauth2' | ||
|
||
module OmniAuth | ||
module Strategies | ||
class OsmOauth2 < OmniAuth::Strategies::OAuth2 | ||
# Give your strategy a name. | ||
option :name, "osm_oauth2" | ||
|
||
# This is where you pass the options you would pass when | ||
# initializing your consumer from the OAuth gem. | ||
option :client_options, {:site => "https://www.openstreetmap.org", | ||
:authorize_url => "https://www.openstreetmap.org/oauth2/authorize", | ||
:token_url => "https://www.openstreetmap.org/oauth2/token"} | ||
|
||
# These are called after authentication has succeeded. If | ||
# possible, you should try to set the UID without making | ||
# additional calls (if the user id is returned with the token | ||
# or as a URI parameter). This may not be possible with all | ||
# providers. | ||
|
||
extra do | ||
{ | ||
'raw_info' => raw_info | ||
} | ||
end | ||
|
||
uid { raw_info['id'] } | ||
|
||
info do | ||
raw_info | ||
end | ||
|
||
def raw_info | ||
@raw_info ||= parse_info(access_token.get('/api/0.6/user/details').body) | ||
@raw_info | ||
rescue ::Errno::ETIMEDOUT | ||
raise ::Timeout::Error | ||
end | ||
|
||
|
||
private | ||
def parse_info(xml_data) | ||
# extract event information | ||
doc = REXML::Document.new(xml_data) | ||
user = doc.elements['//user'] | ||
|
||
basic_attributes = { } | ||
basic_attributes['id'] = user.attribute('id').value if user | ||
basic_attributes['display_name'] = user.attribute('display_name').value if user | ||
|
||
basic_attributes | ||
end | ||
|
||
|
||
end | ||
end | ||
end |