如何使用Javascript和访问令牌移动到另一个页面?

如何使用Javascript和访问令牌移动到另一个页面?,javascript,jquery,oauth-2.0,Javascript,Jquery,Oauth 2.0,这个问题已经解决了几十亿次了,但我很难找到自己的路。我有一个后端服务,它向OAuth2令牌授予用户/密码。当用户登录时,我希望浏览器转到下一页。问题是,这样的页面只能通过auth头访问。方法,如document.location.href=”http://nextpage“不要让我设置授权头,比如authorization=Bearer 1234567890 用户单击“登录”按钮时运行的代码为: var json = { grant_type: "password", client_id

这个问题已经解决了几十亿次了,但我很难找到自己的路。我有一个后端服务,它向OAuth2令牌授予用户/密码。当用户登录时,我希望浏览器转到下一页。问题是,这样的页面只能通过auth头访问。方法,如
document.location.href=”http://nextpage“
不要让我设置授权头,比如
authorization=Bearer 1234567890

用户单击“登录”按钮时运行的代码为:

var json = {
  grant_type: "password",
  client_id: "myClient",
  username: email, // <--- comes from a form
  password: password, // <--- comes from a form
  client_secret: "mySecret"
};

$.ajax({
  url: "http://localhost:9000/auth/token/grant",
  method: 'POST',
  contentType: "application/json",
  dataType: 'json',
  data: JSON.stringify(json),
  cache: false,
  success: function (data) {
    localStorage.authToken = data.access_token;
    localStorage.refreshToken = data.refresh_token;

    // Here I would like to move the browser to the next page
    document.location.href = "http://localhost:9000/nextPage";

  }.bind(this),
  error: function (xhr, status, err) {
    console.error("login request error: ", status, err.toString());
  }.bind(this)
});
var json={
授权类型:“密码”,
客户id:“我的客户”,

用户名:email,//服务器必须提供标题..您可以将其存储在服务器端会话中并以这种方式提供。感谢@MikeC的评论。我想移动到同一域上的页面这一事实可能会与其他问题有所不同?