Skip to content

Commit

Permalink
Add support for generating TOTP cookies
Browse files Browse the repository at this point in the history
This allows other sites in the openstreetmap.org domain to validate
that requests are coming from a www.openstreetmap.org user.
  • Loading branch information
tomhughes committed Jan 2, 2017
1 parent 08b0cbb commit 17135ca
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ gem "faraday"
# Load geoip for querying Maxmind GeoIP database
gem "geoip"

# Load rotp to generate TOTP tokens
gem "rotp"

# Load memcache client in case we are using it
gem "dalli"
gem "kgio"
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ GEM
ref (2.0.0)
request_store (1.3.1)
rinku (2.0.2)
rotp (3.3.0)
rubocop (0.46.0)
parser (>= 2.3.1.1, < 3.0)
powerpack (~> 0.1)
Expand Down Expand Up @@ -373,6 +374,7 @@ DEPENDENCIES
rails-i18n (~> 4.0.0)
redcarpet
rinku (>= 1.2.2)
rotp
rubocop
sanitize
sass-rails (~> 5.0)
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/site_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ def index
unless STATUS == :database_readonly || STATUS == :database_offline
session[:location] ||= OSM.ip_location(request.env["REMOTE_ADDR"])
end

if defined?(TOTP_KEY)
cookies["_osm_totp_token"] = {
:value => ROTP::TOTP.new(TOTP_KEY, :interval => 3600).now,
:domain => ".openstreetmap.org",
:expires => 1.day.from_now
}
end
end

def permalink
Expand Down
2 changes: 2 additions & 0 deletions config/example.application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ defaults: &defaults
#mapzen_valhalla_key: ""
# Thunderforest authentication details
#thunderforest_key: ""
# Key for generating TOTP tokens
#totp_key: ""

development:
<<: *defaults
Expand Down

0 comments on commit 17135ca

Please sign in to comment.