我的一个身份验证问题的工作,其中我要实现我的应用程序做出反应的OAuth2.0身份验证。有没有我可以使用基于爱可信承诺库,验证任何方式???
你必须通过你的令牌在头中。
见下文;
const instance = axios.create({
baseURL: 'http://localhost/api/',
headers: {'Authorization': 'basic '+ token}
});
instance.get('/path')
.then(response => {
return response.data;
})
要么
一旦你得到你的令牌在浏览器中设置的授权cookie。浏览器总是会发送授权cookie中向服务器发出的每个请求。你将不必通过爱可信GET / POST传递给它。
更新:
为了获得从服务器的OAuth访问令牌,通过CLIENT_ID,client_secret,范围和grant_type如下:
var axios = require("axios");
axios.request({
url: "/oauth/token",
method: "post",
baseURL: "http://sample.oauth.server.com/",
auth: {
username: "myUsername", // This is the client_id
password: "myPassword" // This is the client_secret
},
data: {
"grant_type": "client_credentials",
"scope": "public"
}
}).then(respose => {
console.log(respose);
});
我假设你正在使用grant_type =“client_credentials”,如果没有,那么根据您使用grant_type,你也必须相应地改变请求参数。