【问题标题】:'InvalidRequest URL query parameters are not allowed' Django-oauth2 500 error'InvalidRequest URL 查询参数不允许'Django-oauth2 500 错误
【发布时间】:2020-03-03 18:11:06
【问题描述】:

前缀:我是 django 新手。

堆栈:oAuth2 + PKCE 协议、Angular、Django-oauth2-toolkit + REST

继续获取:

oauthlib.oauth2.rfc6749.errors.InvalidRequestError: (invalid_request) URL query parameters are not allowed <oauthlib.Request SANITIZED>

没有关于请求内容的错误细节。

当我在 Angular 中使用 pkce 格式的 POST 请求访问 django oauth2 服务器时,例如

 requestToken(code: string, state: string) {
    const clientState = sessionStorage.getItem('pkce-state');
    if (clientState !== state) {
      console.error('States do not match!');
    }
    const verifier = sessionStorage.getItem('pkce-verifier');

    return this.http.post('http://localhost:8000/o/token/',
      {
        headers: new HttpHeaders({'Content-Type': 'application/x-www-form-urlencoded'})
      },
      {
        params:
          new HttpParams()
            .set('grant_type', 'authorization_code')
            .set('code', code)
            .set('redirect_uri', 'http://localhost:4200/dashboard')
            .set('client_id', 'CLIENT_ID')
            .set('state', state)
            .set('verifier', verifier)
      });
    }

不知道出了什么问题。

P.S 在 django 日志中打印请求时,看起来没有任何编码。挑战和验证者正在工作,否则错误将表明如此。

【问题讨论】:

    标签: python-3.x angular django-rest-framework oauth-2.0 pkce


    【解决方案1】:

    发现删除 httpParams 并将参数添加为 body 不会引发错误 500。现在我有另一个错误,但至少请求格式更准确。

        return this.http.post('http://localhost:8000/o/token/',
      {
        grant_type: 'authorization_code',
        redirect_uri: 'http://localhost:4200/dashboard',
        client_id: 'CLIENT_ID',
        code,
        state,
        verifier
      },
      {
        headers: new HttpHeaders({'Content-Type': 'application/x-www-form-urlencoded'})
      },
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多