Làm thế nào lấy giá trị auth code trong node js

Đây là đoạn code trong goode dev

<!-- Last part of BODY element in file index.html -->
<script>
function signInCallback(authResult) {
  if (authResult['code']) {

    // Hide the sign-in button now that the user is authorized, for example:
    $('#signinButton').attr('style', 'display: none');

    // Send the code to the server
    $.ajax({
      type: 'POST',
      url: 'http://example.com/storeauthcode',
      // Always include an `X-Requested-With` header in every AJAX request,
      // to protect against CSRF attacks.
      headers: {
        'X-Requested-With': 'XMLHttpRequest'
      },
      contentType: 'application/octet-stream; charset=utf-8',
      success: function(result) {
        // Handle or verify the server response.
      },
      processData: false,
      data: authResult['code']
    });
  } else {
    // There was an error.
  }
}
</script>

Trong node js làm sao đọc giá trị này ,
authResult[‘code’]

Nhờ ace chỉ giúp

Đây là client request ajax thông thường mà, đã sử dụng tới nodejs đâu, biến đó là biến global rồi, bạn muốn truy cập lúc nào cũng được.

Nên thêm callback success trên ajax call rồi get nó là được.

Nó đang gửi về server và mình muốn lấy nó:

app.post('/storeauthcode',function(req,res){
       var code=????
})

https://developers.google.com/identity/sign-in/web/server-side-flow#step_7_exchange_the_authorization_code_for_an_access_token

cái này nó demo cách lấy bằng java và python thôi không thấy node js!!!

Bạn xem trong req.body hoặc log req để tìm nhé

Thấy nó rỗng tuếch bạn ạ, mình ra {}, Có giải pháp nào khác không?

sử dụng oauth2 google đi dùng platform của google lại phải include thư viện của google nữa + ko hiểu đc cơ chế auth

Hix đoạn code đó là trong trang web chính thống của google dev, tuy nhiên mình tìm ra rồi, mấu chốt là ở chỗ

application/octet-stream;

Phải in ra file mới lấy được, đoản thế chớ lị.

dùng oauth2 thì làm cái auth facebook tương tự luôn :smiley:

Uh, mình thấy nó cũng ngồ ngộ nên tìm hiểu thôi, chứ mình không theo hướng này. Nó thật ra tìm hiểu về social login thấy trăm hoa đua nở luôn.

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?