/* ============================================================================ * Copyright (c) Palo Alto Networks * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * ========================================================================== */ import React from "react"; import { translate } from "@docusaurus/Translate"; import FormItem from "@theme/ApiExplorer/FormItem"; import FormSelect from "@theme/ApiExplorer/FormSelect"; import FormTextInput from "@theme/ApiExplorer/FormTextInput"; import { useTypedDispatch, useTypedSelector } from "@theme/ApiItem/hooks"; import { OPENAPI_AUTH } from "@theme/translationIds"; import { setAuthData, setSelectedAuth } from "./slice"; function Authorization() { const data = useTypedSelector((state: any) => state.auth.data); const options = useTypedSelector((state: any) => state.auth.options); const selected = useTypedSelector((state: any) => state.auth.selected); const dispatch = useTypedDispatch(); if (selected === undefined) { return null; } const selectedAuth = options[selected]; const optionKeys = Object.keys(options); return (
{optionKeys.length > 1 && ( ) => { dispatch(setSelectedAuth(e.target.value)); }} /> )} {selectedAuth.map((a: any) => { if (a.type === "http" && a.scheme === "bearer") { return ( ) => { const value = e.target.value; dispatch( setAuthData({ scheme: a.key, key: "token", value: value ? value : undefined, }) ); }} /> ); } if (a.type === "oauth2") { return ( ) => { const value = e.target.value; dispatch( setAuthData({ scheme: a.key, key: "token", value: value ? value : undefined, }) ); }} /> ); } if (a.type === "http" && a.scheme === "basic") { return ( ) => { const value = e.target.value; dispatch( setAuthData({ scheme: a.key, key: "username", value: value ? value : undefined, }) ); }} /> ) => { const value = e.target.value; dispatch( setAuthData({ scheme: a.key, key: "password", value: value ? value : undefined, }) ); }} /> ); } if (a.type === "apiKey") { return ( ) => { const value = e.target.value; dispatch( setAuthData({ scheme: a.key, key: "apiKey", value: value ? value : undefined, }) ); }} /> ); } return null; })}
); } export default Authorization;