这是我正在使用的 js OAuth2 库:https ://github.com/andreassolberg/jso
它对我来说效果很好。
提供有关您的应用的信息:
jso_configure({
"your_app": {
client_id: "client id of the application your registered in your provider",
redirect_uri: "http://localhost:8080",
authorization: "https://www.your_app.com/oauth/authorize"
}
});
然后,当您需要时,或者当您的应用程序启动时,授权用户:
jso_ensureTokens({
"your_app": ["public", "write"]
});
就是这样,您现在可以向您的提供程序 api 发送请求:
$.oajax({
url: "https://api.your_app.com/v1/lala/rsvp",
jso_provider: "your_app",
jso_scopes: ["public", "write"],
jso_allowia: true,
dataType: 'json',
success: function(data) {
console.log("Response (your_app):");
console.log(data);
}
});
ps:我不会使用 Authlogic,它太老了。