Skip to content

Instantly share code, notes, and snippets.

@blakejakopovic
Created May 17, 2023 18:16
Show Gist options
  • Select an option

  • Save blakejakopovic/2e8fa806e1b85c17411b66b55f3df4e8 to your computer and use it in GitHub Desktop.

Select an option

Save blakejakopovic/2e8fa806e1b85c17411b66b55f3df4e8 to your computer and use it in GitHub Desktop.

Revisions

  1. blakejakopovic created this gist May 17, 2023.
    30 changes: 30 additions & 0 deletions DummyNostrHttpAuthEndpoint.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    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