TL; DR:從編輯1中讀取。帶有用於移動應用的OAuth的Grails Rest API
我想找到一個解決方案來實現身份驗證,尤其是OAuth,我的休息API將被移動應用程序使用。
我發現這個流行插件(春季安全休息):
http://alvarosanchez.github.io/grails-spring-security-rest/docs/guide/single.html#oauth1
但問題是,它被設計爲JavaScript前端應用程序,因此它需要一個回調URL到我的前端傳遞生成的令牌(如圖中所示)。
對於移動應用程序,我該怎麼做?是否有另一個插件或設計,我可以爲此執行? 我覺得奇怪的是,在Grails或Spring中實際上並沒有大量關於無狀態OAuth的插件或教程,但有大量的移動應用程序使用它。
下面是使用情況的一個例子:
- 用戶打開移動應用程序。
- 用戶通過移動應用程序的臉書登錄。
- 用戶向api /訂單發出一個請求,它將只返回他的訂單。
誰應該在此處理OAuth部分?插件中顯示的圖表中的流程無法與移動應用程序一起使用,那麼應該將移動應用程序授權給Facebook,獲取令牌存儲,然後將其傳遞給Web應用程序?
我想了解什麼是在這種情況下,正確的設計/流程,如果可以去看一個插件或使用Grails來實現它的方式。
編輯:這是一個正確的流量?
如果是的話,有沒有使用Grails來實現這個標準呢?
編輯2:現在我明白了流程,我需要將登錄部分與Spring安全休息插件(已經處理其他所有內容)集成在一起。 這裏,我想用插件集成的代碼,但我不知道在哪裏或什麼插件修改:
// api/auth/fb
def auth(){
//Extract fb_access_token
String fbAccessToken = request.JSON.?fb_access_token
//Call https://graph.facebook.com/me?access_token=fbAccessToken
def userInfo = facebookService. ... (fbAcessToken) //Method to use in the plugin
//Verify if the userInfo contains an error/doesn't contain a fbId
if(userInfo.getFbId() == null){
respond unauthorized() // 401, Invalid access token
}
//Verify if this token is for our app
else if(userInfo.getAppSecret() != System.env.getParameter("appSecret")){
respond unauthorized() //401, token not for this app
}
//Register or login
else{
User user = User.findByFbId(userInfo.getFbId())
if(user == null){
facebookService.registerUser(userInfo) //Custom method implemented in the service
}
else{
FbToken fbToken = new FbToken(userInfo.getToken(), userInfo.getExpiration())
user.setFbAccessToken(fbToken)
}
//Login the user with spring security and let it handle the rest (token creation => storage => http answer)
}
}
你最終有沒有運氣得到這個工作? – OsaSoft 2017-09-23 07:43:36