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

error message:authorization config header is required #6033

Closed
5 tasks done
DDDU123 opened this issue Jul 6, 2024 · 3 comments · Fixed by #6040
Closed
5 tasks done

error message:authorization config header is required #6033

DDDU123 opened this issue Jul 6, 2024 · 3 comments · Fixed by #6040
Labels
🐞 bug Something isn't working

Comments

@DDDU123
Copy link

DDDU123 commented Jul 6, 2024

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.6.12-fix1

Cloud or Self Hosted

Cloud

Steps to reproduce

I got this error message when running the HTTP node: "authorization config header is required." But everything was working fine before yesterday, and I haven't made any changes to the authorization.
企业微信截图_20240706163352企业微信截图_20240706163345

✔️ Expected Behavior

No response

❌ Actual Behavior

No response

@dosubot dosubot bot added the 🐞 bug Something isn't working label Jul 6, 2024
Copy link

dosubot bot commented Jul 6, 2024

Hello, @DDDU123! I'm here to help you with any bugs, questions, or contributions you have for the repository. Let's tackle this issue together!

To resolve the "authorization config header is required" error in Dify version 0.6.12-fix1, ensure that the authorization configuration is correctly set up in your HTTP node. Specifically, you need to provide the required header or API key based on the selected authorization type.

Here is a step-by-step guide to ensure the correct configuration:

  1. Open the Authorization Modal: Ensure that the authorization modal is displayed by setting isShow to true.

  2. Select Authorization Type: Choose the appropriate authorization type (e.g., no-auth or api-key) using the RadioGroup component.

  3. Configure API Key or Header:

    • If you select api-key as the authorization type, you need to further specify the API type (e.g., basic, bearer, or custom).
    • For custom API type, you must provide a header value.
    • For other API types, you need to provide an API key.
  4. Save the Configuration: Ensure that the configuration is saved by clicking the save button, which triggers the handleConfirm function.

Here is the relevant code snippet to guide you through the process:

const handleAuthTypeChange = useCallback((type: string) => {
  const newPayload = produce(tempPayload, (draft: AuthorizationPayloadType) => {
    draft.type = type as AuthorizationType
    if (draft.type === AuthorizationType.apiKey && !draft.config) {
      draft.config = {
        type: APIType.basic,
        api_key: '',
      }
    }
  })
  setTempPayload(newPayload)
}, [tempPayload, setTempPayload])

const handleAuthAPITypeChange = useCallback((type: string) => {
  const newPayload = produce(tempPayload, (draft: AuthorizationPayloadType) => {
    if (!draft.config) {
      draft.config = {
        type: APIType.basic,
        api_key: '',
      }
    }
    draft.config.type = type as APIType
  })
  setTempPayload(newPayload)
}, [tempPayload, setTempPayload])

const handleAPIKeyOrHeaderChange = useCallback((type: 'api_key' | 'header') => {
  return (e: React.ChangeEvent<HTMLInputElement>) => {
    const newPayload = produce(tempPayload, (draft: AuthorizationPayloadType) => {
      if (!draft.config) {
        draft.config = {
          type: APIType.basic,
          api_key: '',
        }
      }
      draft.config[type] = e.target.value
    })
    setTempPayload(newPayload)
  }
}, [tempPayload, setTempPayload])

const handleConfirm = useCallback(() => {
  onChange(tempPayload)
  onHide()
}, [tempPayload, onChange, onHide])

Ensure that you provide the necessary api_key or header value based on the selected API type to avoid the "authorization config header is required" error. According to the HttpRequestNodeData class in the Dify codebase, the Authorization configuration must be a dictionary if the type is not no-auth. This validation ensures that the correct configuration is provided:

class Authorization(BaseModel):
    class Config(BaseModel):
        type: Literal[None, 'basic', 'bearer', 'custom']
        api_key: Union[None, str] = None
        header: Union[None, str] = None

    type: Literal['no-auth', 'api-key']
    config: Optional[Config] = None

    @field_validator('config', mode='before')
    @classmethod
    def check_config(cls, v: Config, values: ValidationInfo):
        if values.data['type'] == 'no-auth':
            return None
        else:
            if not v or not isinstance(v, dict):
                raise ValueError('config should be a dict')
            return v

Make sure your configuration adheres to these requirements to resolve the error [1][2].

To continue talking to Dosu, mention @dosu.

@75py
Copy link
Contributor

75py commented Jul 6, 2024

I found a workaround for this issue. Instead of setting the Bearer authorization as shown in the first image, configure it using the Custom option as shown in the second image. This method works successfully.

Configuration Method Image
Bearer Authorization (does not work) bearer
Custom Authorization (works) custom

@DDDU123
Copy link
Author

DDDU123 commented Jul 6, 2024

我找到了解决此问题的方法。不要像第一张图所示那样设置 Bearer 授权,而是使用第二张图所示的自定义选项进行配置。此方法成功运行。

配置方法 图像
持有人授权(无效) 持票人
自定义授权(作品) 风俗

Yes, it worked fine after I followed your instructions. Thanks! But what puzzles me is that it used to work with Bearer Authorization before. Maybe a new version of Dify introduced a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
2 participants