-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from omniauth/fix-id_token-parsing
Refactor access token rewrite and id_token
- Loading branch information
Showing
3 changed files
with
77 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,6 @@ | |
|
||
module OmniAuth | ||
module Okta | ||
VERSION = '1.0.0'.freeze | ||
VERSION = '2.0.0'.freeze | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,40 @@ | |
|
||
let(:base_url) { 'https://your-org.okta.com' } | ||
let(:strategy) { described_class } | ||
let(:access_token_string) do | ||
"eyJhbGciOiJSUzI1NiJ9.eyJ2ZXIiOjEsImlzcyI6Imh0dHA6Ly9yYWluLm9rdGExLmNvbToxODAyIiwiaWF0IjoxNDQ5Nj" \ | ||
"I0MDI2LCJleHAiOjE0NDk2Mjc2MjYsImp0aSI6IlVmU0lURzZCVVNfdHA3N21BTjJxIiwic2NvcGVzIjpbIm9wZW5pZCIsI" \ | ||
"mVtYWlsIl0sImNsaWVudF9pZCI6InVBYXVub2ZXa2FESnh1a0NGZUJ4IiwidXNlcl9pZCI6IjAwdWlkNEJ4WHc2STZUVjRt" \ | ||
"MGczIn0.HaBu5oQxdVCIvea88HPgr2O5evqZlCT4UXH4UKhJnZ5px-ArNRqwhxXWhHJisslswjPpMkx1IgrudQIjzGYbtLF" \ | ||
"jrrg2ueiU5-YfmKuJuD6O2yPWGTsV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ROeHkfPCaX7KCFO8GgQEkGRoQntFBNjluFhNLJIUkEFovEDlfuB4tv_M" \ | ||
"8BM75celdy3jkpOurg" | ||
end | ||
|
||
let(:okta_response) { | ||
{ | ||
"access_token" => access_token_string, | ||
"token_type" => "Bearer", | ||
"expires_in" => 3600, | ||
"scope" => "openid email", | ||
"refresh_token" => "a9VpZDRCeFh3Nkk2VdY", | ||
"id_token" => id_token_string | ||
} | ||
} | ||
|
||
let(:access_token) { ::OAuth2::AccessToken.from_hash(subject.client, okta_response) } | ||
|
||
describe '#client' do | ||
it 'has default site' do | ||
|
@@ -70,21 +104,46 @@ | |
end | ||
|
||
describe 'extra' do | ||
before :each do | ||
before do | ||
allow(subject).to receive(:raw_info) { { :foo => 'bar' } } | ||
allow(subject).to receive(:access_token) | ||
.and_return( | ||
instance_double(::OAuth2::AccessToken, | ||
token: nil, | ||
refresh_token: 'token', | ||
expires_in: 0, | ||
expires_at: 0)) | ||
allow(subject).to receive(:access_token).and_return(access_token) | ||
end | ||
|
||
it { expect(subject.extra[:raw_info]).to eq({ :foo => 'bar' }) } | ||
it { expect(subject.extra[:id_token]).to eq(id_token_string) } | ||
it { expect(subject.extra[:id_info]).to eq( | ||
{ | ||
"sub" => "00uid4BxXw6I6TV4m0g3", | ||
"email" => "[email protected]", | ||
"email_verified" => true, | ||
"ver" => 1, | ||
"iss" => "http://rain.okta1.com:1802", | ||
"login" => "[email protected]", | ||
"aud" => "uAaunofWkaDJxukCFeBx", | ||
"iat" => 1449624026, | ||
"exp" => 1449627626, | ||
"amr" => ["pwd"], | ||
"jti" => "4eAWJOCMB3SX8XewDfVR", | ||
"auth_time" => 1449624026, | ||
"at_hash" => "cpqKfdQA5eH891Ff5oJr_Q"} | ||
)} | ||
it { expect(subject.access_token).to_not eq(subject.extra[:id_token]) } | ||
end | ||
|
||
describe 'id_token' do | ||
before do | ||
allow(subject).to receive(:access_token).and_return(access_token) | ||
end | ||
|
||
it { expect(subject.id_token).to eq(id_token_string) } | ||
|
||
context 'when access token is nil' do | ||
before do | ||
allow(subject).to receive(:access_token).and_return(nil) | ||
end | ||
|
||
it { expect(subject.id_token).to be_nil } | ||
end | ||
end | ||
|
||
describe 'raw_info' do | ||
|