Skip to content

Commit

Permalink
Use new auth URIs (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
theacodes authored and dazuma committed Aug 1, 2018
1 parent 5f714d4 commit af69fc5
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions lib/googleauth/credentials.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ module Auth
# This class is intended to be inherited by API-specific classes
# which overrides the SCOPE constant.
class Credentials
TOKEN_CREDENTIAL_URI = 'https://accounts.google.com/o/oauth2/token'.freeze
AUDIENCE = 'https://accounts.google.com/o/oauth2/token'.freeze
TOKEN_CREDENTIAL_URI = 'https://oauth2.googleapis.com/token'.freeze
AUDIENCE = 'https://oauth2.googleapis.com/token'.freeze
SCOPE = [].freeze
PATH_ENV_VARS = [].freeze
JSON_ENV_VARS = [].freeze
Expand Down
4 changes: 2 additions & 2 deletions lib/googleauth/user_refresh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ module Auth
#
# cf [Application Default Credentials](http://goo.gl/mkAHpZ)
class UserRefreshCredentials < Signet::OAuth2::Client
TOKEN_CRED_URI = 'https://www.googleapis.com/oauth2/v4/token'.freeze
TOKEN_CRED_URI = 'https://oauth2.googleapis.com/token'.freeze
AUTHORIZATION_URI = 'https://accounts.google.com/o/oauth2/auth'.freeze
REVOKE_TOKEN_URI = 'https://accounts.google.com/o/oauth2/revoke'.freeze
REVOKE_TOKEN_URI = 'https://oauth2.googleapis.com/revoke'.freeze
extend CredentialsLoader

# Create a UserRefreshCredentials.
Expand Down
28 changes: 14 additions & 14 deletions spec/googleauth/credentials_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
allow(mocked_signet).to receive(:fetch_access_token!).and_return(true)
allow(mocked_signet).to receive(:client_id)
allow(Signet::OAuth2::Client).to receive(:new) do |options|
expect(options[:token_credential_uri]).to eq('https://accounts.google.com/o/oauth2/token')
expect(options[:audience]).to eq('https://accounts.google.com/o/oauth2/token')
expect(options[:token_credential_uri]).to eq('https://oauth2.googleapis.com/token')
expect(options[:audience]).to eq('https://oauth2.googleapis.com/token')
expect(options[:scope]).to eq([])
expect(options[:issuer]).to eq(default_keyfile_hash['client_email'])
expect(options[:signing_key]).to be_a_kind_of(OpenSSL::PKey::RSA)
Expand All @@ -66,8 +66,8 @@
allow(mocked_signet).to receive(:fetch_access_token!).and_return(true)
allow(mocked_signet).to receive(:client_id)
allow(Signet::OAuth2::Client).to receive(:new) do |options|
expect(options[:token_credential_uri]).to eq('https://accounts.google.com/o/oauth2/token')
expect(options[:audience]).to eq('https://accounts.google.com/o/oauth2/token')
expect(options[:token_credential_uri]).to eq('https://oauth2.googleapis.com/token')
expect(options[:audience]).to eq('https://oauth2.googleapis.com/token')
expect(options[:scope]).to eq(['http://example.com/scope'])
expect(options[:issuer]).to eq(default_keyfile_hash['client_email'])
expect(options[:signing_key]).to be_a_kind_of(OpenSSL::PKey::RSA)
Expand Down Expand Up @@ -98,8 +98,8 @@ class TestCredentials < Google::Auth::Credentials
allow(mocked_signet).to receive(:fetch_access_token!).and_return(true)
allow(mocked_signet).to receive(:client_id)
allow(Signet::OAuth2::Client).to receive(:new) do |options|
expect(options[:token_credential_uri]).to eq('https://accounts.google.com/o/oauth2/token')
expect(options[:audience]).to eq('https://accounts.google.com/o/oauth2/token')
expect(options[:token_credential_uri]).to eq('https://oauth2.googleapis.com/token')
expect(options[:audience]).to eq('https://oauth2.googleapis.com/token')
expect(options[:scope]).to eq(['http://example.com/scope'])
expect(options[:issuer]).to eq(default_keyfile_hash['client_email'])
expect(options[:signing_key]).to be_a_kind_of(OpenSSL::PKey::RSA)
Expand Down Expand Up @@ -130,8 +130,8 @@ class TestCredentials < Google::Auth::Credentials
allow(mocked_signet).to receive(:fetch_access_token!).and_return(true)
allow(mocked_signet).to receive(:client_id)
allow(Signet::OAuth2::Client).to receive(:new) do |options|
expect(options[:token_credential_uri]).to eq('https://accounts.google.com/o/oauth2/token')
expect(options[:audience]).to eq('https://accounts.google.com/o/oauth2/token')
expect(options[:token_credential_uri]).to eq('https://oauth2.googleapis.com/token')
expect(options[:audience]).to eq('https://oauth2.googleapis.com/token')
expect(options[:scope]).to eq(['http://example.com/scope'])
expect(options[:issuer]).to eq(default_keyfile_hash['client_email'])
expect(options[:signing_key]).to be_a_kind_of(OpenSSL::PKey::RSA)
Expand Down Expand Up @@ -161,8 +161,8 @@ class TestCredentials < Google::Auth::Credentials
allow(mocked_signet).to receive(:fetch_access_token!).and_return(true)
allow(mocked_signet).to receive(:client_id)
allow(Signet::OAuth2::Client).to receive(:new) do |options|
expect(options[:token_credential_uri]).to eq('https://accounts.google.com/o/oauth2/token')
expect(options[:audience]).to eq('https://accounts.google.com/o/oauth2/token')
expect(options[:token_credential_uri]).to eq('https://oauth2.googleapis.com/token')
expect(options[:audience]).to eq('https://oauth2.googleapis.com/token')
expect(options[:scope]).to eq(['http://example.com/scope'])
expect(options[:issuer]).to eq(default_keyfile_hash['client_email'])
expect(options[:signing_key]).to be_a_kind_of(OpenSSL::PKey::RSA)
Expand Down Expand Up @@ -193,8 +193,8 @@ class TestCredentials < Google::Auth::Credentials
allow(mocked_signet).to receive(:fetch_access_token!).and_return(true)
allow(mocked_signet).to receive(:client_id)
allow(Signet::OAuth2::Client).to receive(:new) do |options|
expect(options[:token_credential_uri]).to eq('https://accounts.google.com/o/oauth2/token')
expect(options[:audience]).to eq('https://accounts.google.com/o/oauth2/token')
expect(options[:token_credential_uri]).to eq('https://oauth2.googleapis.com/token')
expect(options[:audience]).to eq('https://oauth2.googleapis.com/token')
expect(options[:scope]).to eq(['http://example.com/scope'])
expect(options[:issuer]).to eq(default_keyfile_hash['client_email'])
expect(options[:signing_key]).to be_a_kind_of(OpenSSL::PKey::RSA)
Expand Down Expand Up @@ -231,8 +231,8 @@ class TestCredentials < Google::Auth::Credentials
default_keyfile_hash
end
allow(Signet::OAuth2::Client).to receive(:new) do |options|
expect(options[:token_credential_uri]).to eq('https://accounts.google.com/o/oauth2/token')
expect(options[:audience]).to eq('https://accounts.google.com/o/oauth2/token')
expect(options[:token_credential_uri]).to eq('https://oauth2.googleapis.com/token')
expect(options[:audience]).to eq('https://oauth2.googleapis.com/token')
expect(options[:scope]).to eq(['http://example.com/scope'])
expect(options[:issuer]).to eq(default_keyfile_hash['client_email'])
expect(options[:signing_key]).to be_a_kind_of(OpenSSL::PKey::RSA)
Expand Down
6 changes: 3 additions & 3 deletions spec/googleauth/signet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
before(:example) do
@key = OpenSSL::PKey::RSA.new(2048)
@client = Signet::OAuth2::Client.new(
token_credential_uri: 'https://accounts.google.com/o/oauth2/token',
token_credential_uri: 'https://oauth2.googleapis.com/token',
scope: 'https://www.googleapis.com/auth/userinfo.profile',
issuer: 'app@example.com',
audience: 'https://accounts.google.com/o/oauth2/token',
audience: 'https://oauth2.googleapis.com/token',
signing_key: @key
)
end
Expand All @@ -60,7 +60,7 @@ def make_auth_stubs(opts)
@key.public_key, true,
algorithm: 'RS256')
end
stub_request(:post, 'https://accounts.google.com/o/oauth2/token')
stub_request(:post, 'https://oauth2.googleapis.com/token')
.with(body: hash_including(
'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer'
), &blk)
Expand Down
8 changes: 4 additions & 4 deletions spec/googleauth/user_authorizer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
end

before(:example) do
stub_request(:post, 'https://www.googleapis.com/oauth2/v4/token')
stub_request(:post, 'https://oauth2.googleapis.com/token')
.to_return(body: token_json, status: 200, headers: {
'Content-Type' => 'application/json'
})
Expand Down Expand Up @@ -270,7 +270,7 @@

context 'with invalid authorization code' do
before(:example) do
stub_request(:post, 'https://www.googleapis.com/oauth2/v4/token')
stub_request(:post, 'https://oauth2.googleapis.com/token')
.to_return(status: 400)
end

Expand Down Expand Up @@ -300,15 +300,15 @@
before(:example) do
token_store.store('user1', token_json)
stub_request(
:get, 'https://accounts.google.com/o/oauth2/revoke?token=refreshtoken'
:get, 'https://oauth2.googleapis.com/revoke?token=refreshtoken'
)
.to_return(status: 200)
end

it 'should revoke the grant' do
authorizer.revoke_authorization('user1')
expect(a_request(
:get, 'https://accounts.google.com/o/oauth2/revoke?token=refreshtoken'
:get, 'https://oauth2.googleapis.com/revoke?token=refreshtoken'
))
.to have_been_made
end
Expand Down
8 changes: 4 additions & 4 deletions spec/googleauth/user_refresh_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def make_auth_stubs(opts = {})
body = MultiJson.dump('access_token' => access_token,
'token_type' => 'Bearer',
'expires_in' => 3600)
stub_request(:post, 'https://www.googleapis.com/oauth2/v4/token')
stub_request(:post, 'https://oauth2.googleapis.com/token')
.with(body: hash_including('grant_type' => 'refresh_token'))
.to_return(body: body,
status: 200,
Expand Down Expand Up @@ -246,7 +246,7 @@ def cred_json_text(missing = nil)

describe 'when revoking a refresh token' do
let(:stub) do
stub_request(:get, 'https://accounts.google.com/o/oauth2/revoke' \
stub_request(:get, 'https://oauth2.googleapis.com/revoke' \
'?token=refreshtoken')
.to_return(status: 200,
headers: { 'Content-Type' => 'application/json' })
Expand All @@ -262,7 +262,7 @@ def cred_json_text(missing = nil)

describe 'when revoking an access token' do
let(:stub) do
stub_request(:get, 'https://accounts.google.com/o/oauth2/revoke' \
stub_request(:get, 'https://oauth2.googleapis.com/revoke' \
'?token=accesstoken')
.to_return(status: 200,
headers: { 'Content-Type' => 'application/json' })
Expand All @@ -280,7 +280,7 @@ def cred_json_text(missing = nil)

describe 'when revoking an invalid token' do
let(:stub) do
stub_request(:get, 'https://accounts.google.com/o/oauth2/revoke' \
stub_request(:get, 'https://oauth2.googleapis.com/revoke' \
'?token=refreshtoken')
.to_return(status: 400,
headers: { 'Content-Type' => 'application/json' })
Expand Down
2 changes: 1 addition & 1 deletion spec/googleauth/web_user_authorizer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
end

before(:example) do
stub_request(:post, 'https://www.googleapis.com/oauth2/v4/token')
stub_request(:post, 'https://oauth2.googleapis.com/token')
.to_return(body: token_json,
status: 200,
headers: { 'Content-Type' => 'application/json' })
Expand Down

0 comments on commit af69fc5

Please sign in to comment.