2016-04-27 14 views
0

Ich entwickle Phonegap/Cordova Crossplatform App. Und ich möchte mich über LINE account einloggen.LINE Anwendung Login API Auth2 funktioniert nicht

ich Unterricht in https://developers.line.me/web-login/integrating-web-login befolgt haben, die ich meine channel_id haben, client_secret, Set callback_url (http://localhost)

I unten verwenden Link Login-Seite von LINE-Anwendung zu öffnen

https://access.line.me/dialog/oauth/weblogin?response_type=code&client_id=channel_id & redirect_uri = http://localhost&state=

nachdem ich LOGIN-Taste drücken, um es zu https://access.line.me/dialog/oauth/authorize mit Text Rückruf sagte: „Es gibt Probleme mit dem Login Sie waren Sie eine Weile warten, bevor es erneut versuchen..“ - Ich habe gewartet und versucht erneut aber es funktioniert nie.

var lineapi = { 
     authorize: function(options) { 
      var deferred = $.Deferred(); 

      //Build the OAuth consent page URL 
      //https://access.line.me/dialog/oauth/weblogin?response_type=code&client_id={Channel ID}&redirect_uri={Redirect URL}&state={State} 
      var authUrl = 'https://access.line.me/dialog/oauth/weblogin?' + $.param({ 
       client_id: options.channel_id, 
       redirect_uri: options.redirect_uri, 
       response_type: 'code', 
       // scope: options.scope, 
       state: '' 
      }); 

      //Open the OAuth consent page in the InAppBrowser 
      var authWindow = window.open(authUrl, '_blank', 'location=no,toolbar=no'); 

      //The recommendation is to use the redirect_uri "urn:ietf:wg:oauth:2.0:oob" 
      //which sets the authorization code in the browser's title. However, we can't 
      //access the title of the InAppBrowser. 
      // 
      //Instead, we pass a bogus redirect_uri of "http://localhost", which means the 
      //authorization code will get set in the url. We can access the url in the 
      //loadstart and loadstop events. So if we bind the loadstart event, we can 
      //find the authorization code and close the InAppBrowser after the user 
      //has granted us access to their data. 
      $(authWindow).on('loadstart', function(e) { 
       console.log('loadstart:',e); 
       var url = e.originalEvent.url; 
       console.log("url:",url); 
       var code = /\?code=(.+)$/.exec(url); 
       var error = /\?error=(.+)$/.exec(url); 
       var callback = /\?callback=(.+)$/.exec(url); 

       if (code || error) { 
        //Always close the browser when match is found 
        authWindow.close(); 
       } 

       if (code) { 
        //Exchange the authorization code for an access token 
        console.log('calling oauth for accessToken'); 
        $.post('https://api.line.me/v1/oauth/accessToken', { 
         grant_type: 'authorization_code', 
         client_id: options.channel_id, 
         client_secret: options.channel_secret, 
         code: code, 
         redirect_uri: options.redirect_uri 
        }).done(function(data) { 
         alert(data); 
         deferred.resolve(data); 
        }).fail(function(response) { 
         alert(response); 
         deferred.reject(response.responseJSON); 
        }); 
       } else if (error) { 
        //The user denied access to the app 
        console.log("error:",error); 
        deferred.reject({ 
         error: error[1] 
        }); 
       } 
      }); 

      return deferred.promise(); 
     } 
    }; 

    $scope.loginLine = function(){ 

    lineapi.authorize({ 
     channel_id: ***my_channel_id***, 
     channel_secret: ***my_channel_secret***, 
     redirect_uri: 'http://localhost', 
     scope: 'PROFILE' 
    }); 
    } 

Kann jemand das beheben? Sehr geschätzt für Ihre Hilfe.

Antwort

0

haben Sie einen Blick auf die entsprechende URL in der Adresszeile, nachdem Sie eingeben E-Mail/Passwort Zugangsdaten im Login-Formular Zeile - diese Fehlermeldung wie folgt enthalten:

https://access.line.me/dialog/oauth/weblogin?response_type=code&forceSecondVerification=false&userId=XXX%40XXXXXX.com&client_id=XXXXXXXXX&showPermissionApproval=&displayType=b&idProvider=1&redirect_uri=http%3A%2F%2Flocalhost%3A4000%2Fauth%2Fline%2Fcallback&state=&lang=&errorCode=400&errorMessage=AUTH_INVALID_REDIRECT_URL 

In meinem Beispiel habe ich ungültig URL und Fehlermeldung umleiten errorMessage=AUTH_INVALID_REDIRECT_URL

als Ihr oauth URL enthält localhost auch ich nehme Ihre errorMessage werden die gleichen sein.

Die Dokumentation here sagt:

Die Redirect-URL einer der angegebenen URLs übereinstimmen müssen, wenn Ihr Kanal Registrierung. Das Vergleichsziel ist vom Schema zum Pfad der URL. Der Abfrageparameter ist nicht als Vergleichsziel enthalten. Geben Sie eine URL-codierte Zeichenfolge an, um den Abfrageparameterwert anzugeben.