walid
walid

Reputation: 492

google auth1 to oauth2 migration: Invalid authorization header

I've a script to migrate from google oauth1 to oauth2 using oauth gem

everything seems right and i can't detect any problem with the headers but it still responding with: Invalid authorization header.

Here're the headers:

opening connection to accounts.google.com:443... opened starting SSL for accounts.google.com:443... SSL established <- "POST /o/oauth2/token HTTP/1.1\r\nContent-Type: application/x-www-form-urlencoded\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nAccept: /\r\nUser-Agent: OAuth gem v0.4.7\r\nContent-Length: 193\r\nAuthorization: OAuth oauth_consumer_key=\"mykey.com\", oauth_nonce=\"LdBeaxxxxxxxxxxxxxxIxgd03U1DHYbs\", oauth_signature=\"wXIuxxxxxxxyxxxxj0%3D\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"1416497830\", oauth_token=\"1%2F9G2sKmQxxxxxxxxxxmDXbqqifoRBGUAii-D5sw2o\", oauth_version=\"1.0\"\r\nConnection: close\r\nHost: accounts.google.com\r\n\r\n"

<- "client_id=the_id&client_secret=C-7xxxxxxxxxboMcinh3ofV&grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Amigration%3Aoauth1"> "HTTP/1.1 400 Bad Request\r\n"

-> "Content-Type: application/json\r\n"

-> "Cache-Control: no-cache, no-store, max-age=0, must-revalidate\r\n"

-> "Pragma: no-cache\r\n"

-> "Expires: Fri, 01 Jan 1990 00:00:00 GMT\r\n"

-> "Date: Thu, 20 Nov 2014 12:37:03 GMT\r\n"

-> "X-Content-Type-Options: nosniff\r\n"

-> "X-Frame-Options: SAMEORIGIN\r\n"

-> "X-XSS-Protection: 1; mode=block\r\n"

-> "Server: GSE\r\n"

-> "Alternate-Protocol: 443:quic,p=0.01\r\n"

-> "Connection: close\r\n"

-> "\r\n"

reading all...

-> "{\n \"error\" : \"invalid_request\",\n \"error_description\" : \"Invalid authorization header.\"\n}"

read 90 bytes Conn close

and here's the code:

oauth1_consumer_key    = "mykey"
oauth1_consumer_secret = "Gxxxxxxxxxxxxxxxxqb8"

# OAuth 1 - User Token / Secret.
oauth1_token           = '1/9G2xxxxxxxxxxxxxxsw2o'
oauth1_secret          = 'a-xxxxxxxxxxxxxxxmqG'

# OAuth 2 - Application ID / Secret
oauth2_client_id       = "the_id"
oauth2_client_secret   = "C-xxxxxxxxxxxxxxxxV"

# Migration Parameters.
params = {
  "grant_type"             => "urn:ietf:params:oauth:grant-type:migration:oauth1",
  "client_id"              => oauth2_client_id,
  "client_secret"          => oauth2_client_secret,
  # "oauth_signature_method" => "HMAC-SHA1"
}

# Create the consumer object.
consumer = OAuth::Consumer.new(
  oauth1_consumer_key,
  oauth1_consumer_secret,
  :site   => 'https://accounts.google.com',
  :scheme => :header
)


# Create the access token object.
access_token = OAuth::AccessToken.new(consumer, oauth1_token, oauth1_secret)

resp = access_token.post(
  "/o/oauth2/token",
  params,
  { 'Content-Type' => 'application/x-www-form-urlencoded' })

if resp.code.to_s != "200"
  # Raise an error.
  raise "#{resp.code} - #{resp.body}"
end

Any ideas?

Upvotes: 2

Views: 426

Answers (1)

walid
walid

Reputation: 492

After updating the oauth gem, I tried it again and it worked.

Upvotes: 1

Related Questions