Skip to content

Instantly share code, notes, and snippets.

@blakejakopovic
Created May 17, 2023 18:16
Show Gist options
  • Save blakejakopovic/2e8fa806e1b85c17411b66b55f3df4e8 to your computer and use it in GitHub Desktop.
Save blakejakopovic/2e8fa806e1b85c17411b66b55f3df4e8 to your computer and use it in GitHub Desktop.
Dummy Nostr HTTP AUTH endpoint for NIP-98
require 'sinatra'
get '/public/AUTHIMAGE.jpg' do
auth_header = request.env['HTTP_AUTHORIZATION']
puts auth_header
# Check if the header value starts with "Nostr "
unless auth_header && auth_header.start_with?("Nostr ")
headers['WWW-AUTHENTICATE'] = 'NOSTR-NIP-98'
headers['Access-Control-Expose-Headers'] = 'WWW-Authenticate'
headers['Access-Control-Allow-Origin'] = '*'
halt 401, 'Unauthorized'
end
begin
# Read the image file
file_path = 'public/AUTHIMAGE.jpg'
if File.exist?(file_path)
send_file file_path, type: 'image/jpeg'
else
halt 404, 'Not Found'
end
rescue
halt 500, 'Internal Server Error'
end
end
# Start the Sinatra server
set :port, 9550
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment