小编Al *_* Po的帖子

FusionTables私人表与OAUTH2

蒂姆罗森伯格的好照片,显示了OAUTH2的工作方式:

在此输入图像描述

我甚至懒得开始查看这2个 文件并进行测试, 所以我搜索了最简单的方法

1.get令牌

2.使用该令牌访问

gwt-oauth2的帮助下

把它放到index.php头: <script type="text/javascript" src="gwt-oauth2.js"></script>

这在体内

<script type="text/javascript">
(function() {
var GOOGLE_AUTH_URL = "https://accounts.google.com/o/oauth2/auth";
var GOOGLE_CLIENT_ID = "CLIENT_ID";
//var PLUS_ME_SCOPE = "https://www.googleapis.com/auth/plus.me";
//var FusionTable_SCOPE = "https://www.googleapis.com/auth/fusiontables";       
var button = document.createElement("button");
button.innerText = "Authenticate with Google";
button.onclick = function() {

var req = {
    'authUrl' : GOOGLE_AUTH_URL,
    'clientId' : GOOGLE_CLIENT_ID,
    'scopes': ['https://www.googleapis.com/auth/plus.me',
               'https://www.googleapis.com/auth/fusiontables'
              ],
};

oauth2.login(req, function(token) {
    alert('Got an OAuth token:\n'+ token +'\n'+ 'Token expires in '+ …
Run Code Online (Sandbox Code Playgroud)

javascript oauth-2.0 google-fusion-tables

18
推荐指数
1
解决办法
3120
查看次数

在directions_changed上刷新路标

我自己做了一个路线经理,有几个选项(比如avoidTolls travelMode avoidHighways waypoints)和可拖动的路线.

我创建var lastRequest = []DirectionsRequest properties从最后一个渲染存储.

代码如下所示:

directionsService.route(request, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
        var directions = parseDirections(response, mode, tolls)
        directionsDisplay.setDirections(response)
    }
});

google.maps.event.addListener(directionsDisplay, 'directions_changed', function() {
    refreshReq(directionsDisplay.getDirections())
})

function refreshReq(response)
{
    //
}
Run Code Online (Sandbox Code Playgroud)

我很难找到一个解决方案来刷新directions_changedlastRequest['waypoints']的新数据,response所以我的脚本将能够存储一个路标对象并重做lastRequest我想要的任何时间.

当我从response我需要的路径阵列中取出时会遇到困难

试过几个变种:
lastRequest['waypoints'] = response['routes'][0]['legs'][0]['via_waypoints']
但事实并非如此.

下一步是逐个重新生成每个路点,new google.maps.LatLng()但由于某种原因,即使我用eval()将它们推入数组后也无法工作.

将中途停留更改为false/true,尝试了不同的东西,但没有,必须遗漏一些东西.

javascript javascript-events google-maps-api-3

8
推荐指数
1
解决办法
2423
查看次数

JWT 计算签名 SHA256withRSA

我试图

使用从 API 控制台获取的私钥,使用 SHA256withRSA(也称为 RSASSA-PKCS1-V1_5-SIGN 和 SHA-256 哈希函数)对输入的 UTF-8 表示进行签名。输出将是一个字节数组。

所以让我们把 Header 和 Claim 设置成数组

{"alg":"RS256","typ":"JWT"}.
{
  "iss":"761326798069-r5mljlln1rd4lrbhg75efgigp36m78j5@developer.gserviceaccount.com",
  "scope":"https://www.googleapis.com/auth/prediction",
  "aud":"https://accounts.google.com/o/oauth2/token",
  "exp":1328554385,
  "iat":1328550785
}
Run Code Online (Sandbox Code Playgroud)

就像服务帐户:计算签名

JSON Web 签名 (JWS) 是指导为 JWT 生成签名的机制的规范。签名的输入是以下内容的字节数组

{ Base64url 编码的标头}.{ Base64url 编码的声明集}

所以我构建数组只是为了测试

  $seg0 = array(
    "alg" => "RS256",
    "typ" => "JWT"
  );
  $seg1 = array(
    "iss" => "761326798069-r5mljlln1rd4lrbhg75efgigp36m78j5@developer.gserviceaccount.com",
    "scope" => "https://www.googleapis.com/auth/prediction",
    "aud" => "https://accounts.google.com/o/oauth2/token",
    "exp" => 1328554385,
    "iat" => 1328550785
  );

  $segs = array(
    json_encode($seg0),
    stripslashes(json_encode($seg1))
  ); …
Run Code Online (Sandbox Code Playgroud)

php oauth-2.0

5
推荐指数
1
解决办法
2432
查看次数