2

Facebookトークンを使用してDjango-social-authでDjangoプロジェクトのユーザーを認証するためのcurlリクエストを正常に使用して、個人サイトのトークンを返しています。簡単に言えば、私は Facebook トークンを持っていて、それを Django トークンに変換していますが、CURL リクエストを使用してこの偉業を成し遂げているだけです。私が使用しているフレームワークは Philip Garnero (1) のものです。

CURL リクエスト - curl -X POST -d "grant_type=convert_token&client_id=&client_secret=&backend=facebook&token=" http://localhost:8000/auth/convert-token

AJAX リクエストを使用してこれを実行しようとすると、混乱が生じます。私のajaxのセットアップ方法に何か問題がありますか? Facebook トークンを認証済み Django トークンに変換する前に、まず csrf トークンを取得する必要がありますか?

更新: プロキシ経由で ajax リクエストを実行しているときに、400 エラー unsupported_grant_type が発生します。このリクエストは、curl コマンドと Postman コマンドの両方で正常に実行したリクエストと同じです。

Ajax リクエスト:

$http({
        url: "proxy/url/...",
        async: false,
        crossDomain: true,  
        method: "POST",
        data: {
          "client_id": "...",
          "client_secret": "...",
          "grant_type": "password",
          "username": "...",
          "password": "..."
        },
        headers: {
              'Content-Type': 'application/x-www-form-urlencoded'
        }        
        }).success(function(data, status, headers, config) {
            console.log(data);
        }).error(function(data, status, headers, config) {
            console.log("error status = " + status);
            console.log(angular.toJson(data));
        });

(1) - https://github.com/PhilipGarnero/django-rest-framework-social-oauth2

4

1 に答える 1