2017-08-24 84 views
1

我創建了一個彈簧啓動OAuth2 JWT MySQL,如指定的here,並發現用戶正在驗證當我運行下面的捲曲請求。如何驗證彈簧啓動OAuth2 JWT從離子

curl -X POST -vu clientapp:123456 http://localhost:8080/oauth/token -H "Accept: application/json" -d "password=papidakos123&username=papidakos&grant_type=password&scope=read%20write&client_secret=123456&client_id=clientapp" 

現在我需要用這個作爲後端爲我的應用離子,但我是新來這個離子應用程序的開發,不知道如何從離子應用到我的春季安全的oauth2服務器進行身份驗證。我搜索了它,但發現其中大部分都使用社交簽名與谷歌,臉譜等。我不知道從離子前端認證過程和存儲訪問和刷新令牌和分配的角色。請幫助我用一個例子來開發這個。

回答

0

使用http模塊,你可以做一個POST請求到服務器,然後就可以使用NativeStorage

constructor(public nativeStorage : NativeStorage){ 

} 

postRequest() { 
    var headers = new Headers(); 
    headers.append("Accept", 'application/json'); 
    headers.append('Content-Type', 'application/json'); 
    let options = new RequestOptions({ 
    headers: headers 
    }); 


    let postParams = { 
    password: papidakos123, 
    username: papidakos, 
    grant_type: password, 
    scope = read % 20 write, 
    client_secret = 123456, 
    client_id = clientapp 
    } 

    this.http.post("http://localhost:8080/oauth/token", postParams, options) 
    .subscribe(data => { 
     if(data.success){ 
     //Handle success 
     //this.nativeStorage.set('token',data.token).catch(err=>{ 
     //handle storage error 
     }); 
    } 
    }, error => { 
     console.log(error); 
    }); 
} 

根據不同的響應,你可以使用RxJS設置的登錄狀態存儲在localStorage的權杖用戶。請參考這Github Source

+0

你能告訴我一個完整的例子與登錄pages.I是新離子發展。 – KJEjava48

+0

我添加了一個來源到我的答案。請參考。 –

+0

好的謝謝你,但它是安全的使用http而不是https – KJEjava48