Posted to tcl by mjanssen at Sun Jul 31 08:24:38 GMT 2016view raw
- set key $googleApplicationKey
- set secret $googleApplicationSecret
- package require http
- # Google APIs require https
- package require http
- package require tls
- http::register https 443 ::tls::socket
- # Listen for an OAuth2 callback
- proc accept {chan addr port} { ;# Make a proc to accept connections
- puts "Google says [gets $chan]" ;# Receive a string
- puts $chan goodbye ;# Send a string
- close $chan ;# Close the socket (automatically flushes)
- } ;#
- proc start {cmd} {
- exec {*}[auto_execok start] "" $cmd
- }
- socket -server accept 12345 ;# Create a server socket
- set endpoint https://accounts.google.com/o/oauth2/v2/auth
- set params [list response_type code]
- lappend params client_id $key
- lappend params redirect_uri http://127.0.0.1:12345
- lappend params scope profile
- lappend params state "somerandomstringyoushouldcheckonreturntoprevent MIM attacks"
- set result [http::geturl $endpoint -query [http::formatQuery {*}$params]]
- upvar #0 $result state
- puts "Copy this URL to your browser: [dict get $state(meta) Location]"