Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c66d980
Clear the sessionStorage when logging out (#1003)
AMoo-Miki Jun 1, 2022
1c58c32
Bump version to 2.1.0.0 (#1004)
cliu123 Jun 2, 2022
32eec67
Dynamically compute OpenID redirectUri from proxy HTTP headers (#929)
jaycci Jun 8, 2022
40478f5
Disable private tenant for read only users (#868)
hsiang9431-amzn Jun 9, 2022
08092a4
Fix OIDC looping issue - too many redriects (#1014)
aoguan1990 Jun 24, 2022
46980c8
Adds snapshot management cluster permissions (#1016)
downsrob Jun 24, 2022
d66016e
Adds release notes for 2.1.0 (#1015)
DarshitChanpura Jun 27, 2022
a53eab0
Updates Dev guide (#897)
DarshitChanpura Jun 29, 2022
6182907
Add tests for account-nav-button when multitenancy is disabled (#1020)
cwperks Jul 6, 2022
520d9cd
Get security_tenant search param from URL (#1024)
cliu123 Jul 7, 2022
546dd81
Fix bug in support for jwt.url_param customization (#1025)
cwperks Jul 7, 2022
0d51611
Revert "Replace _opendistro route with _plugins (#895)" (#1035)
DarshitChanpura Jul 20, 2022
a6bf095
fix-expiration-of-token-from-actual-idtoken
Jul 23, 2022
cccfd75
fix-expiration-of-token-from-actual-idtoken
Jul 23, 2022
04ffaeb
fix-expiration-of-token-from-actual-idtoken
Jul 23, 2022
5adca5b
fix-expiration-of-token-from-actual-idtoken
Jul 23, 2022
d4aba7a
fix-expiration-of-token-from-actual-idtoken
Jul 24, 2022
913f917
fix-expiration-of-token-from-actual-idtoken
Jul 28, 2022
766a07e
fix-expiration-of-token-from-actual-idtoken
Jul 28, 2022
257d9ea
Revert "Revert "Replace _opendistro route with _plugins (#895)" (#1035)"
Jul 28, 2022
27488bd
fix-expiration-of-token-from-actual-idtoken
Aug 5, 2022
1e6a952
Revert "Replace _opendistro route with _plugins (#895)" (#1035)
DarshitChanpura Jul 20, 2022
e45afa4
Revert "Revert "Replace _opendistro route with _plugins (#895)" (#1035)"
Jul 28, 2022
fdc1d0b
fix-expiration-of-token-from-actual-idtoken
Jul 23, 2022
b26ccea
fix-expiration-of-token-from-actual-idtoken
Jul 23, 2022
e0bacde
Merge branch 'main' into fix-expiration-of-token-from-actual-idtoken
Aug 8, 2022
c2a15e5
Merge branch 'main' into fix-expiration-of-token-from-actual-idtoken
peternied Aug 8, 2022
a8cc750
Merge branch 'main' into fix-expiration-of-token-from-actual-idtoken
DarshitChanpura Aug 23, 2022
326c154
Merge branch 'main' into fix-expiration-of-token-from-actual-idtoken
peternied Aug 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion server/auth/types/openid/helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* permissions and limitations under the License.
*/

import { composeLogoutUrl, getRootUrl } from './helper';
import { composeLogoutUrl, getExpirationDate, getRootUrl } from './helper';

describe('test OIDC helper utility', () => {
test('test compose logout url', () => {
Expand Down Expand Up @@ -137,4 +137,13 @@ describe('test OIDC helper utility', () => {

expect('http://server.com:80').toEqual(getRootUrl(config, core, request));
});

test('extract expiration time from jwt token', () => {
expect(1658582700000).toEqual(
getExpirationDate({
idToken:
'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Imtld2lRcTlqaUM4NEN2U3NKWU9CLU42QThXRkxTVjIwTWIteTdJbFdEU1EifQ.eyJpc3MiOiJodHRwczovL2dpdGxhYi5jb20iLCJzdWIiOiI5ODc5ODQ1IiwiYXVkIjoiOTkzZWM3MTA3YjNlZmJiZTRkZDdjYmE1NDRmMDU4YTMyMmIwN2M0ZmQ5MTljMzdkMGM4ODQ5MjljYzVkM2U5NiIsImV4cCI6MTY1ODU4MjcwMCwiaWF0IjoxNjU4NTgyNTgwLCJhdXRoX3RpbWUiOjE2NTgzMjU1ODgsInN1Yl9sZWdhY3kiOiIxYWNiYzI5ZGFkOWViMGI0MjM3YTVhMTEzNzg2M2E4ZDNlNDFkOGRjOWJhMzJlYzFkOGIwMWJjODY5NzczMGM0IiwiZ3JvdXBzX2RpcmVjdCI6WyJlb3NmaW50ZWsiLCJlNDM4NyJdfQ.CVgOC3K4e95cOY2akmGBWJcSGjkyO517N_784ob2Tj3aeMpyk-O_OsbUhmt_Fu_XvqSk5dY02c1a8Ngav8_7MOsHb6MovYQsnIE0ddxtJSY2uswOWX53cE2SPU-G-s8vVLX-MfIG1_Mfg2cYE-eL2nRlSSrMug9IXiiWGoQuS0vrjuomgoq3gZnNCM-Yn-2TI3YZSsluyaODMnW2yVCeu8ZMJp6ZbCMBwAwq-dMVENF9jEHJqtRgOOP1OXJ9scapS14IHXaUrHkxlyRDRYKMZ727hQs_aMHZAlLyycz_9xI2RgZ4dTOldbXZeBUrOZvwe5ZMdok3a9LYr91clFu-pA24zHFUeFqjcVRMxhYZAD4wYdG26pYk1Otk9auvSaPd6Rsk4fK_tA7hVWCM1NMO1lhQ0RzLl4MRKx4NJrjm4jlodUGx3k_js2YtXYdKGNwWcm2ESTUgPdL1dQus3ll5Lr_wt5uY3GYjCtDA6BcZWhRewgWdmJ8hPx8JNuz3Sw2bDxjgmZqCQ4I4WMa-HncAshfZY-mLlWOkxN9kzHSXIZGa-No6_u9JZwfKdZXkK9UJMAuY4SH5PcvJitVAVDPg6EQa1Ne8AkVFOBfPF0_S3QZnW4D7kRNhs0pr-eyBb3cUACLPjS4maCccQ6MSBZ9RYy3l0wgitRv2SVIBvBH0eN4',
})
);
});
});
16 changes: 16 additions & 0 deletions server/auth/types/openid/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,19 @@ export interface TokenResponse {
refreshToken?: string;
expiresIn?: number;
}

export function getExpirationDate(tokenResponse: TokenResponse | undefined) {
if (!tokenResponse) {
throw new Error('Invalid token');
} else if (tokenResponse.idToken) {
const idToken = tokenResponse.idToken;
const parts = idToken.split('.');
if (parts.length !== 3) {
throw new Error('Invalid token');
}
const claim = JSON.parse(Buffer.from(parts[1], 'base64').toString());
return claim.exp * 1000;
} else {
return Date.now() + tokenResponse.expiresIn! * 1000;
}
}
3 changes: 2 additions & 1 deletion server/auth/types/openid/openid_auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { OpenIdAuthRoutes } from './routes';
import { AuthenticationType } from '../authentication_type';
import { callTokenEndpoint } from './helper';
import { composeNextUrlQueryParam } from '../../../utils/next_url';
import { getExpirationDate } from './helper';

export interface OpenIdAuthConfig {
authorizationEndpoint?: string;
Expand Down Expand Up @@ -189,7 +190,7 @@ export class OpenIdAuthentication extends AuthenticationType {
cookie.credentials = {
authHeaderValue: `Bearer ${refreshTokenResponse.idToken}`,
refresh_token: refreshTokenResponse.refreshToken,
expires_at: Date.now() + refreshTokenResponse.expiresIn! * 1000, // expiresIn is in second
expires_at: getExpirationDate(refreshTokenResponse), // expiresIn is in second
};
return true;
} else {
Expand Down
4 changes: 2 additions & 2 deletions server/auth/types/openid/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { OpenIdAuthConfig } from './openid_auth';
import { SecurityClient } from '../../../backend/opensearch_security_client';
import { getBaseRedirectUrl, callTokenEndpoint, composeLogoutUrl } from './helper';
import { validateNextUrl } from '../../../utils/next_url';
import { getExpirationDate } from './helper';

export class OpenIdAuthRoutes {
private static readonly NONCE_LENGTH: number = 22;
Expand Down Expand Up @@ -148,7 +149,6 @@ export class OpenIdAuthRoutes {
query,
this.wreckClient
);

const user = await this.securityClient.authenticateWithHeader(
request,
this.openIdAuthConfig.authHeaderName as string,
Expand All @@ -160,7 +160,7 @@ export class OpenIdAuthRoutes {
username: user.username,
credentials: {
authHeaderValue: `Bearer ${tokenResponse.idToken}`,
expires_at: Date.now() + tokenResponse.expiresIn! * 1000, // expiresIn is in second
expires_at: getExpirationDate(tokenResponse),
},
authType: 'openid',
expiryTime: Date.now() + this.config.session.ttl,
Expand Down