Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Bounty Hunting things #48

Open
Rootharsh opened this issue Mar 15, 2023 · 1 comment
Open

Bug Bounty Hunting things #48

Rootharsh opened this issue Mar 15, 2023 · 1 comment

Comments

@Rootharsh
Copy link

No description provided.

@ThreatLEVELred
Copy link

require "sinatra"
require "dotenv/load"
require "net/http"
require "json"

CLIENT_ID = ENV.fetch("CLIENT_ID")
CLIENT_SECRET = ENV.fetch("CLIENT_SECRET")

def parse_response(response)
case response
when Net::HTTPOK
JSON.parse(response.body)
else
puts response
puts response.body
{}
end
end

def exchange_code(code)
params = {
"client_id" => CLIENT_ID,
"client_secret" => CLIENT_SECRET,
"code" => code
}
result = Net::HTTP.post(
URI("https://github.com/login/oauth/access_token"),
URI.encode_www_form(params),
{"Accept" => "application/json"}
)

parse_response(result)
end

def user_info(token)
uri = URI("https://api.github.com/user")

result = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
body = {"access_token" => token}.to_json

auth = "Bearer #{token}"
headers = {"Accept" => "application/json", "Content-Type" => "application/json", "Authorization" => auth}

http.send_request("GET", uri.path, body, headers)

end

parse_response(result)
end

get "/" do
link = 'Login with GitHub'
erb link
end

get "CALLBACK_URL" do
code = params["code"]

token_data = exchange_code(code)

if token_data.key?("access_token")
token = token_data["access_token"]

user_info = user_info(token)
handle = user_info["login"]
name = user_info["name"]

render = "Successfully authorized! Welcome, #{name} (#{handle})."
erb render

else
render = "Authorized, but unable to exchange code #{code} for token."
erb render
end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants