使用 OAuth 和 javascript 的应用程序 [英] application that uses OAuth and javascript

查看:20
本文介绍了使用 OAuth 和 javascript 的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算创建一个使用 JavaScript 的应用程序,它需要使用 OAuth 来验证网站用户的身份.有人可以帮我吗?任何示例代码?我知道 Google Code Javascript OAuth 库,但我不确定如何实现它..

解决方案

这里有一个 OAuth 的 JS 客户端实现:https://developers.google.com/identity/protocols/OAuth2UserAgent>

它包含让您运行的示例代码.基本上,你要做的是:

var url = "...";var 访问器 = {令牌:...",tokenSecret: "...",消费者密钥:...",消费者秘密:……"};变量消息 = {行动:网址,方法:获取",参数: {...}};OAuth.completeRequest(message, accessor);OAuth.SignatureMethod.sign(message, accessor);网址 = 网址 + '?'+ OAuth.formEncode(message.parameters);//向'url'发送请求...

干杯,马蒂亚斯

I am planning to create an app that uses JavaScript and it needs to use OAuth to authenticate user for a website. Can anyone help me out please? Any sample code? I know about the Google Code Javascript OAuth library but I am not sure how to implement that..

解决方案

There is a JS client implementation for OAuth here: https://developers.google.com/identity/protocols/OAuth2UserAgent

It contains example code to get you running. Basically, what you do is this:

var url = "...";
var accessor = {
  token: "...",
  tokenSecret: "...",
  consumerKey : "...",
  consumerSecret: "..."
};

var message = {
  action: url,
  method: "GET",
  parameters: {...}
};

OAuth.completeRequest(message, accessor);        
OAuth.SignatureMethod.sign(message, accessor);
url = url + '?' + OAuth.formEncode(message.parameters);

// send request to 'url'
...

Cheers, Matthias

这篇关于使用 OAuth 和 javascript 的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆