相关疑难解决方法(0)

Google使用Javascript API登录而不触发弹出窗口

我使用以下代码让用户能够通过Javascript API使用他们的Google帐户登录.

HTML

<a id="gp_login" href="javascript:void(0)" onclick="javascript:googleAuth()">Login using Google</a>

使用Javascript

function gPOnLoad(){
     // G+ api loaded
     document.getElementById('gp_login').style.display = 'block';
}
function googleAuth() {
    gapi.auth.signIn({
        callback: gPSignInCallback,
        clientid: googleKey,
        cookiepolicy: "single_host_origin",
        requestvisibleactions: "http://schema.org/AddAction",
        scope: "https://www.googleapis.com/auth/plus.login email"
    })
}

function gPSignInCallback(e) {
    if (e["status"]["signed_in"]) {
        gapi.client.load("plus", "v1", function() {
            if (e["access_token"]) {
                getProfile()
            } else if (e["error"]) {
                console.log("There was an error: " + e["error"])
            }
        })
    } else {
        console.log("Sign-in state: " + e["error"])
    }
}

function getProfile() {
    var e …
Run Code Online (Sandbox Code Playgroud)

javascript jquery google-api google-plus google-oauth

9
推荐指数
2
解决办法
1万
查看次数

使用Firebase Auth访问Google Calendar API

我正在使用AngularJS,Firebase(SDK v3)和Google Calendar API构建Web应用程序.我正在使用Google OAuth对用户进行身份验证.我的目的是能够从Firebase中的数据库节点创建日历事件.到目前为止,我已设法请求访问日历范围:

_authProvider = new firebase.auth.GoogleAuthProvider();
// Get permission to manage Calendar
_authProvider.addScope("https://www.googleapis.com/auth/calendar");
_fbAuthObject.signInWithRedirect(_authProvider);
Run Code Online (Sandbox Code Playgroud)

我正在使用重定向流进行身份验证,因此身份验证重定向可用:

_fbAuthObject.getRedirectResult()
    .then(function _readToken(result) {
      if (result.credential) {
        _googleToken = result.credential.accessToken;
        var authHeader = 'Bearer '+ _googleToken;

        // Just a test call to the api, returns 200 OK 
        $http({
          method: 'GET',
          headers: {
            'Authorization': authHeader
          },
          url: 'https://www.googleapis.com/calendar/v3/users/me/calendarList/primary'
        })
          .then(function success(response) {
            console.log('Cal response', response);
          },
          function error(response) {
            console.log('Error', response);
          });
Run Code Online (Sandbox Code Playgroud)

但是,在初始登录之外,似乎无法通过Firebase SDK获取Google访问令牌.似乎只能访问Firebase JWT令牌,而不能使用Calendar API.我可以存储访问令牌,但这不能解决刷新令牌等问题.有没有办法通过Firebase SDK获取当前的Google Access令牌,如果没有,那么有什么其他解决方案可以解决问题两次验证用户?

更新1:

好像其他人一直在努力解决与Facebook身份验证相似的问题.在该问题上,有一个指向Firebase文档 …

authentication google-calendar-api angularjs firebase firebase-authentication

9
推荐指数
1
解决办法
4158
查看次数

Firebase 3 - javascript - 登录后获取facebook accessToken

在Firebase 2中,我可以accessToken通过这种方式从登录后的任何地方获取Facebook ,只需使用firebase引用,例如:

firebase.getAuth().facebook.accessToken
Run Code Online (Sandbox Code Playgroud)

现在,我怎样才能在版本3(Web)中获得它?

注意,我需要在Promise之外 signInWithPopup

谢谢

javascript firebase firebase-security firebase-authentication

3
推荐指数
2
解决办法
4168
查看次数