Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Wiring up new auth object
Browse files Browse the repository at this point in the history
  • Loading branch information
domharrington committed Jan 25, 2019
1 parent 8e6ddbd commit bb52222
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
16 changes: 6 additions & 10 deletions packages/api-explorer/src/Doc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Doc extends React.Component {
this.waypointEntered = this.waypointEntered.bind(this);
this.Params = createParams(this.oas);

this.setApiKey();
this.setAuth();
}

onChange(formData) {
Expand Down Expand Up @@ -79,20 +79,17 @@ class Doc extends React.Component {
});
}

setApiKey() {
// TODO make sure this works again to set the api key in the initial code sample
// needs to work for both && and || securities
setAuth() {
if (!this.props.user) return;

const operation = this.getOperation();

if (!operation) return;

try {
this.state.formData.auth = this.operation.getSecurity().map((securityRequirement) => {
return Object.keys(securityRequirement).map((name) => {
this.oas.components.securitySchemes[name]._key = name;
return { [name]: getAuth(this.props.user, this.oas.components.securitySchemes[name]) };
}).reduce((prev, next) => Object.assign(prev, next));
}).reduce((prev, next) => Object.assign(prev, next), {})
this.state.formData.auth = getAuth(this.props.user, operation);
} catch (e) {
// console.warn('There was a problem setting the api key on', operation.operationId, 'This probably just means there is no auth on this endpoint'); // eslint-disable-line no-console
}
Expand Down Expand Up @@ -301,7 +298,7 @@ class Doc extends React.Component {
toggleAuth={this.toggleAuth}
onSubmit={this.onSubmit}
authInputRef={el => (this.authInput = el)}
user={this.props.user}
auth={this.state.formData.auth}
/>
);
}
Expand Down Expand Up @@ -403,7 +400,6 @@ Doc.propTypes = {
baseUrl: PropTypes.string,
oauth: PropTypes.bool.isRequired,
suggestedEdits: PropTypes.bool.isRequired,
apiKey: PropTypes.string,
tryItMetrics: PropTypes.func.isRequired,
};

Expand Down
8 changes: 4 additions & 4 deletions packages/api-explorer/src/PathUrl.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function PathUrl({
toggleAuth,
onSubmit,
oauth,
user,
auth,
}) {
return (
<div className="api-definition-parent">
Expand All @@ -45,7 +45,7 @@ function PathUrl({
toggle={toggleAuth}
authInputRef={authInputRef}
oauth={oauth}
user={user}
auth={auth}
/>

<button
Expand Down Expand Up @@ -97,14 +97,14 @@ PathUrl.propTypes = {
showAuthBox: PropTypes.bool,
needsAuth: PropTypes.bool,
oauth: PropTypes.bool.isRequired,
user: PropTypes.shape({}),
auth: PropTypes.shape({}),
};

PathUrl.defaultProps = {
showAuthBox: false,
needsAuth: false,
authInputRef: () => {},
user: {},
auth: {},
};
module.exports = PathUrl;
module.exports.splitPath = splitPath;
1 change: 1 addition & 0 deletions packages/api-explorer/src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ApiExplorer extends React.Component {
selected: '',
changeSelected: this.changeSelected,
},
auth: {},
};
}

Expand Down

0 comments on commit bb52222

Please sign in to comment.