簡體   English   中英

Erlang中的Google Oauth2

[英]Google Oauth2 in Erlang

如何在Erlang中生成Google oauth2訪問令牌。

我可以在NodejS i中生成令牌。 我在Erlang中需要它,因為我所有的其他api代碼都在Erlang中。

大段引用

var {google} = require('googleapis');
var MESSAGING_SCOPE = "https://www.googleapis.com/auth/firebase.messaging";
var SCOPES = [MESSAGING_SCOPE];

 var http = require('http')


 function getAccessToken(){
    return new Promise(function(resolve, reject){
        var key = require("./ServiceAccountKey.json");
        var jwtClient = new google.auth.JWT(
            key.client_email,
            null,
            key.private_key,
            SCOPES,
            null
        );
        jwtClient.authorize(function(err, tokens){
            if(err){
                reject(err);
                return; 
            }
            resolve(tokens.access_token+" :  "+tokens.expiry_date);
        });
    });
}

 var server = http.createServer(function(req, res){

     getAccessToken().then(function(access_token){

         res.end(access_token);

     });

 });

 server.listen(3000, function(){
    console.log("Server started");
}); 

試圖生成代碼

 URL="https://accounts.google.com/o/oauth2/auth",
 Scope="https://www.googleapis.com/auth/firebase.messaging",

 GetURL=URL++"?client_id="++ClientId++"&redirect_uri=com.example.app:/oauth2redirect&scope="++Scope++"&response_type=code",

        Response = httpc:request(URL),
        Response.

返回錯誤請求

在您的代碼中,您正在創建一個包含所有必需查詢參數的URL並將其放入變量GetURL ,但是您將URL (只是基本URL)傳遞給httpc:request 嘗試傳遞GetURL ,看看是否能讓你更進一步:

    Response = httpc:request(GetURL),

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM