Created
November 11, 2023 23:45
-
-
Save mackuba/a6c2a922be8895c2b82c93e54272b86d to your computer and use it in GitHub Desktop.
Bluesky login with federation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# "proper" way, more future- and federation-proof | |
handle = form.get('handle') | |
password = form.get('password') | |
if dns_record = lookup_dns("_atproto.#{handle}") | |
did = did_from_dns(dns_record) | |
elsif res = open_url("https://#{handle}/.well-known/atproto-did") | |
did = did_from_well_known(res) | |
else | |
raise "handle could not be resolved" | |
end | |
if did.type == 'plc' | |
did_doc = open_url("https://plc.directory/#{did}") | |
elsif did.type == 'web' | |
did_doc = open_url("https://#{host}/.well-known/did.json") | |
else | |
raise "unknown did type" | |
end | |
pds_host = did_doc['service'][0]['serviceEndpoint'] | |
client = Client.new(pds_host) | |
client.log_in(handle, password) | |
client.post("hello world") | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# shortcut via appview | |
handle = form.get('handle') | |
password = form.get('password') | |
appview = Client.new('api.bsky.app') | |
did = appview.resolveHandle(handle) | |
if did.type == 'plc' | |
did_doc = open_url("https://plc.directory/#{did}") | |
elsif did.type == 'web' | |
did_doc = open_url("https://#{host}/.well-known/did.json") | |
else | |
raise "unknown did type" | |
end | |
pds_host = did_doc['service'][0]['serviceEndpoint'] | |
client = Client.new(pds_host) | |
client.log_in(handle, password) | |
client.post("hello world") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment