Posted to tcl by mjanssen at Sun Jul 31 08:24:38 GMT 2016view raw

  1. set key $googleApplicationKey
  2. set secret $googleApplicationSecret
  3. package require http
  4.  
  5. # Google APIs require https
  6. package require http
  7. package require tls
  8. http::register https 443 ::tls::socket
  9. # Listen for an OAuth2 callback
  10.  
  11. proc accept {chan addr port} { ;# Make a proc to accept connections
  12. puts "Google says [gets $chan]" ;# Receive a string
  13. puts $chan goodbye ;# Send a string
  14. close $chan ;# Close the socket (automatically flushes)
  15. } ;#
  16.  
  17.  
  18. proc start {cmd} {
  19. exec {*}[auto_execok start] "" $cmd
  20. }
  21.  
  22. socket -server accept 12345 ;# Create a server socket
  23.  
  24.  
  25. set endpoint https://accounts.google.com/o/oauth2/v2/auth
  26.  
  27. set params [list response_type code]
  28. lappend params client_id $key
  29. lappend params redirect_uri http://127.0.0.1:12345
  30. lappend params scope profile
  31. lappend params state "somerandomstringyoushouldcheckonreturntoprevent MIM attacks"
  32.  
  33. set result [http::geturl $endpoint -query [http::formatQuery {*}$params]]
  34. upvar #0 $result state
  35. puts "Copy this URL to your browser: [dict get $state(meta) Location]"