2016-03-31 16 views
0

Durandal kullanan tek bir sayfa uygulamasına sahibim. Sayfalardan birinde, web servisini aramak için kullandığım bir jetonu almak için OAuth 2 ile kimlik doğrulaması yapmam gerekiyor. Tek sayfamdaki uygulama durumumu kaybetmek istemiyorum, bu nedenle OAuth yetkilendirmesini yeni bir pencerede gerçekleştirmek istiyorum.Durandal tek sayfa uygulamasında OAuth2 ile doğrulama

Şu anda sahip olduğum çözülmemiş sorun, alt pencereden ana pencereye OAuth belirtecini geçiriyor. Çocuk penceresinden jetonu ebeveyn penceresindeki Durandal uygulamasına koymanın bir yolunu bulmaya çalıştım ama hiçbir çözüm bulamadım. Sonunda ana pencerenin bir özelliğine koymaya karar verdim, ama hala işe yaramıyor.

activate: function() { 
    var authTokenDeffered = $.Deferred(); 

    if (!window.myAuthToken) { 
     var authWindow = window.open(
      "https://oauth.myprovider.com/authorize?response_type=token&client_id=98599205d0aa4837a074cc19163bd38e&display=popup", 
      "_blank", "modal=yes,alwaysRaised=yes"); 

     var checkConnect = setInterval(function() { 
      if (!authWindow || !authWindow.closed) return; 
      clearInterval(checkConnect); 

      // I expect token here, but I do not get it 
      console.log(window.myAuthToken); 

      authTokenDeffered.resolve(window.myAuthToken); 
     }, 100); 
    } else { 
     authTokenDeffered.resolve(window.myAuthToken) 
    } 

    var campaigns = this.campaigns; 
    return authTokenDeffered.then(function (authToken) { 
     http.get('https://myprovider.com/my-service', {}, {'Authorization': 'Bearer ' + authToken}) 
      .then(function (response) { campaigns(response); }); 
    }); 
}, 

OAuth 2 geri arama sayfası aşağıdaki komut dosyası vardır:

var token = /access_token=([0-9a-f]+)/.exec(document.location.hash)[1]; 
window.parent.myAuthToken = token; 
window.close(); 

cevap

0

ebeveyne veri aktarmak için doğru yolu

window.opener.myAuthToken = token; 
İşte

benim modül kodudur
İlgili konular