Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CL-16691: Support Okta Access token #148

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
6 changes: 6 additions & 0 deletions src/Classy/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ class Classy {
DEFAULT_STRICT_SSL
);

this.oktaBaseUrl = (
!_.isUndefined(config.oktaBaseUrl) ?
config.oktaBaseUrl :
''
);

/**
* Add the ability to define an error logger.
*
Expand Down
4 changes: 2 additions & 2 deletions src/ClassyResource/_makeRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { utils } from '../utils';
* @param {object} form Request form (optional)
* @return {promise} Promise based on API request
*/
export default function _makeRequest(path, method, headers = {}, form, data = {}) {
export default function _makeRequest(path, method, headers = {}, form, data = {}, baseUrl = null) {
let forceQs = null;

if (data.noLog) {
Expand All @@ -32,7 +32,7 @@ export default function _makeRequest(path, method, headers = {}, form, data = {}
: undefined;

const requestParams = {
baseUrl: this.baseUrl,
baseUrl: baseUrl ? baseUrl : this.baseUrl,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does this.baseUrl get set? I'd prefer that we update that value in the appropriate place if config.oktaBaseUrl is passed in.

Copy link
Author

@vyerawar vyerawar Jun 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.baseUrl is set in src/ClassyResource/main.js. In that we are not getting request payload to check is_okta_token flag.
I am removing this change from here and updating the this.baseUrl value in src/ClassyResource/createMethod.js file. I have updated the code, please review.

uri: path,
method: method,
headers: headers,
Expand Down
9 changes: 8 additions & 1 deletion src/ClassyResource/createMethod.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,19 @@ export default function createMethod(spec) {
}

if (response === 'member') {

let baseUrl = this._classy.baseUrl;
// Gateway url to support okta based member token
if (_.get(data, 'token.is_okta_token', false)) {
baseUrl = this._classy.oktaBaseUrl;
}

const memberToken = _.get(data, 'token.access_token', false);
delete data.token;

requestHeaders.Authorization = 'Bearer ' + memberToken;

return this._makeRequest(requestPath, requestMethod, requestHeaders, form, data);
return this._makeRequest(requestPath, requestMethod, requestHeaders, form, data, baseUrl);
}

}, (error) => {
Expand Down