Created
December 5, 2010 04:19
-
-
Save esprehn/728788 to your computer and use it in GitHub Desktop.
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
# DeviantART Auth Token | |
# Zeros-Elipticus | |
# 4-12-2010 | |
require 'net/https' | |
require 'uri' | |
# Get a token, optionally asking dA to generate a brand new one | |
# if reusetoken is false. | |
# | |
# Performs an http request against chat.deviantart.com to ensure the | |
# new token can be used with dAmn. | |
# | |
def get_token(username, password, reusetoken=true) | |
uri = URI.parse('https://www.deviantart.com/users/login') | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true if uri.scheme == "https" | |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
http.start do | |
data = URI.encode("username=#{username}&password=#{password}&reusetoken=#{reusetoken and 1 or 0}") | |
http.request_post(uri.path,data) do |res| | |
if( res.get_fields('location') and | |
res.get_fields('location')[0] == 'http://www.deviantart.com/users/loggedin' and | |
(token = URI.decode(res['Set-Cookie']).match('"authtoken";s:32:"([a-f0-9]{32})";'))) | |
cookie = res['Set-Cookie'] | |
# Make cookie usable in dAmn by doing an http request to chat.deviantart.com | |
enable_token(cookie) if cookie | |
return token[1] | |
end | |
end | |
end | |
nil | |
end | |
# Enables a token's use with dAmn. | |
# | |
def enable_token(cookie) | |
uri = URI.parse('http://chat.deviantart.com/chat/devart') | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.start do |http| | |
request = Net::HTTP::Get.new(uri.path) | |
request['Cookie'] = cookie | |
http.request(request) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment