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

Commit bb52222

Browse files
committed
Wiring up new auth object
1 parent 8e6ddbd commit bb52222

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

packages/api-explorer/src/Doc.jsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Doc extends React.Component {
4242
this.waypointEntered = this.waypointEntered.bind(this);
4343
this.Params = createParams(this.oas);
4444

45-
this.setApiKey();
45+
this.setAuth();
4646
}
4747

4848
onChange(formData) {
@@ -79,20 +79,17 @@ class Doc extends React.Component {
7979
});
8080
}
8181

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

8587
const operation = this.getOperation();
8688

8789
if (!operation) return;
8890

8991
try {
90-
this.state.formData.auth = this.operation.getSecurity().map((securityRequirement) => {
91-
return Object.keys(securityRequirement).map((name) => {
92-
this.oas.components.securitySchemes[name]._key = name;
93-
return { [name]: getAuth(this.props.user, this.oas.components.securitySchemes[name]) };
94-
}).reduce((prev, next) => Object.assign(prev, next));
95-
}).reduce((prev, next) => Object.assign(prev, next), {})
92+
this.state.formData.auth = getAuth(this.props.user, operation);
9693
} catch (e) {
9794
// 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
9895
}
@@ -301,7 +298,7 @@ class Doc extends React.Component {
301298
toggleAuth={this.toggleAuth}
302299
onSubmit={this.onSubmit}
303300
authInputRef={el => (this.authInput = el)}
304-
user={this.props.user}
301+
auth={this.state.formData.auth}
305302
/>
306303
);
307304
}
@@ -403,7 +400,6 @@ Doc.propTypes = {
403400
baseUrl: PropTypes.string,
404401
oauth: PropTypes.bool.isRequired,
405402
suggestedEdits: PropTypes.bool.isRequired,
406-
apiKey: PropTypes.string,
407403
tryItMetrics: PropTypes.func.isRequired,
408404
};
409405

packages/api-explorer/src/PathUrl.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function PathUrl({
2828
toggleAuth,
2929
onSubmit,
3030
oauth,
31-
user,
31+
auth,
3232
}) {
3333
return (
3434
<div className="api-definition-parent">
@@ -45,7 +45,7 @@ function PathUrl({
4545
toggle={toggleAuth}
4646
authInputRef={authInputRef}
4747
oauth={oauth}
48-
user={user}
48+
auth={auth}
4949
/>
5050

5151
<button
@@ -97,14 +97,14 @@ PathUrl.propTypes = {
9797
showAuthBox: PropTypes.bool,
9898
needsAuth: PropTypes.bool,
9999
oauth: PropTypes.bool.isRequired,
100-
user: PropTypes.shape({}),
100+
auth: PropTypes.shape({}),
101101
};
102102

103103
PathUrl.defaultProps = {
104104
showAuthBox: false,
105105
needsAuth: false,
106106
authInputRef: () => {},
107-
user: {},
107+
auth: {},
108108
};
109109
module.exports = PathUrl;
110110
module.exports.splitPath = splitPath;

packages/api-explorer/src/index.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class ApiExplorer extends React.Component {
2525
selected: '',
2626
changeSelected: this.changeSelected,
2727
},
28+
auth: {},
2829
};
2930
}
3031

0 commit comments

Comments
 (0)