Not sure if you have made progress. I had to struggle through some
things with my service provider,
but after that, I had a problem like yours because I forgot to set the
connect to use_ssl
So, something like this works for me (adapted form Peter Winer's
suggestion
http://github.com/stuart/google-authsub/tree/master/lib/googleauthsub.rb
)
method = Net::HTTP.get
url = Net::HTTPS.build(:host => "
www.google.com", :path => "/accounts/
AuthSubSessionToken")
request = method.new(url.path)
request['Authorization'] = google_auth(url, once_token)
#once_token is what you got and need to exchange for a session token
#google_auth described below
request['Content-Type'] = "application/x-new-form-urlencoded"
logger.info(request.to_yaml) #I found this very helpful - the yaml
format is easy to read
connection = Net::HTTP.new(url.host, url.port)
connection.use_ssl = true #don't forget this
response = connection.start {|http| http.request(request) }
session_token = response.body.match(/^Token-(.*)$/([1]
where the google_auth function is like so
def google_auth(url, t)
time = Time.now.toi.to_s
nonce = OpenSSL::BN.rand_range(2**64)
data = "GET #{url} #{time} #{nonce}"
f = File.new(File.join(RAILS_ROOT, 'config', 'keys.pem'))
key = OpenSSL::PKey::RSA.new(f.read)
sig = key.sign(OpenSSL::Digest::SHA1.new, (data))
sig = Base64.b64encode(sig).gsub(/\n/, '')
return "AuthSub token=\"#{t}\" sigalg=\"rsa-sha1\" data=\"#data}\"
sig=\"#{sig}\""
end
Note that I haven't put in error checking for the connection process
Also, I found that I could not successfully read a pem file that had
been created by openssl
I had to create the file with Ruby's facilities, and then Ruby's
OpenSSL::PKey::RAS.new would work
Also, I need to put the key into a constant rather than reading it
every time I need a token.
But , hopefully this may help you
On Jul 26, 4:45 am, sgudibanda <
sgudiba...@gmail.com> wrote:
> I get 403 status code, even if i pass in some arbitrary value . sig
> =kljlkjljlk gives me the same error.
> I am doing something completely stupid?
>
> On Jul 26, 11:47 am, sgudibanda <
sgudiba...@gmail.com> wrote:
>
> > Thanks mtz. Now i can key in my passphrase directly in there.
> > But i am still receiving 401 status back though.
> > Any suggestions?
>
> > On Jul 25, 3:05 am, mtz <
tracey.zellm...@gmail.com> wrote:
>
> > > I might be able to help you with the first point.
>
> > > Therubymethod for getting the key from the file takes an optional