如何在 JAVA 中将 facebook 身份验证添加到我的 Rest 应用程序
我与Jersey创建了一个Restful应用程序,现在我正在尝试将Facebook身份验证接口添加到我的应用程序中,并且我有点坚持如何将身份验证连接到我的REST方法。
package service;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import metier.Cours;
@Path("rs")
public class Formation {
@GET
@Produces(MediaType.TEXT_PLAIN)
@Path("/FraisAnnuelles/{code}")
public Double FraisInscription(@PathParam(value="code")int code) {
return (Double)(30000+(Math.random()*(30000-25000)));
}
@GET
@Path("/Cours/{code}")
@Produces(MediaType.APPLICATION_XML)
public Cours getCours(@PathParam(value="code")int code) {
return new Cours(code,"web semantique",30);
}
@GET
@Path("/ListeCours")
@Produces(MediaType.APPLICATION_XML)
public List<Cours> getAllCours(){
List<Cours> listeCours=new ArrayList<>();
listeCours.add(new Cours(1,"web semantique",30));
listeCours.add(new Cours(2,"web service",20));
listeCours.add(new Cours(3,"IAD",26));
return listeCours;
}
}
I created a RESTful application with jersey and now I'm trying to add a facebook authentication interface to my app and i'm kinda stuck how to connect authentication to my rest method .
package service;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import metier.Cours;
@Path("rs")
public class Formation {
@GET
@Produces(MediaType.TEXT_PLAIN)
@Path("/FraisAnnuelles/{code}")
public Double FraisInscription(@PathParam(value="code")int code) {
return (Double)(30000+(Math.random()*(30000-25000)));
}
@GET
@Path("/Cours/{code}")
@Produces(MediaType.APPLICATION_XML)
public Cours getCours(@PathParam(value="code")int code) {
return new Cours(code,"web semantique",30);
}
@GET
@Path("/ListeCours")
@Produces(MediaType.APPLICATION_XML)
public List<Cours> getAllCours(){
List<Cours> listeCours=new ArrayList<>();
listeCours.add(new Cours(1,"web semantique",30));
listeCours.add(new Cours(2,"web service",20));
listeCours.add(new Cours(3,"IAD",26));
return listeCours;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定你是否能够做到这一点。用于通过 facebook/google/some_identity_provider 登录的协议是
OpenID 连接。从头开始时,这本身就是一大堆蠕虫,但我对您所要求的可行性有一些怀疑的关键因素是,要成功使用 openid connect 登录,身份提供者有一个数据库表,其中包含允许登录的 url 列表,除非您尝试登录的 url 与该表中的值之一完全 100% 匹配,否则登录尝试将失败。
所以换句话来说,为了让用户能够在 https://myblog.example 上使用 facebook/google 登录。 com/blog 您需要联系 facebook/google 并询问他们“嘿 facebook/google,您可以添加 https://myblog.example.com/blog 到允许从 Pretty 登录的 URL 列表?”。我认为这两家公司在允许登录之前都要求您的网站具有一定的(显着的)最小尺寸,并且您将完全随心所欲地接受他们的条款和条件,并且谈判的可能性为零。您可能需要为特权付费才能使用它们作为身份提供商。
I am not sure if you will be able to do that. The protocol that is used for logging in with facebook/google/some_identity_provider is
OpenID connect. That itself is a big can of worms to dive into when starting from scratch, but the key element in why I have some doubts to the feasibility of what you are asking for is that for a login using openid connect to be successful, the identity provider has a database table with a list of allowed urls to log in from, and unless the url you try to log in from matches exactly 100% one of the values in that table, the login attempt will fail.
So in other words, in order to allow users to log in with facebook/google on https://myblog.example.com/blog you need to contact facebook/google and ask them "hey facebook/google, can you add https://myblog.example.com/blog to the list urls allowed to log in from pretty please?". I assume both companies require some (significant) minimum size of your web site before allowing logging in with them, and you will be absolutely at the whim of their terms and condition with zero negotiation possibilities. You might need to pay for the privileged to use them as identity providers.