Skip to content

Instantly share code, notes, and snippets.

@ShreyanJain9
Created April 17, 2023 20:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShreyanJain9/6b45efe9a3d204d3893934acb5394bdd to your computer and use it in GitHub Desktop.
Save ShreyanJain9/6b45efe9a3d204d3893934acb5394bdd to your computer and use it in GitHub Desktop.
require 'json'
require 'net/http'
require 'date'
module ATProto
class Session
def initialize(username, password)
@atp_host = "https://bsky.social"
@atp_auth_token = ""
@did = ""
@username = username
data = { "identifier" => username, "password" => password }.to_json
uri = URI("#{@atp_host}/xrpc/com.atproto.server.createSession")
response = Net::HTTP.post(uri, data, 'Content-Type' => 'application/json')
parsed_response = JSON.parse(response.body)
@atp_auth_token = parsed_response['accessJwt']
if @atp_auth_token.nil?
raise ValueError.new("No access token, is your password wrong?")
end
@did = parsed_response['did']
end
def getdid()
puts @did
end
end
end
# bsky = ATProto::Session.new(username, password)
# bsky.getdid
@ianklatzco
Copy link

yay!!!!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment