将身份验证令牌传递给服务

时间:2018-05-08 09:23:17

标签: json authentication service liferay

我使用了生活服务构建器来构建我的服务。我的一些服务要求用户在使用之前进行身份验证。

如何生成身份验证令牌并将其发送到标头或网址?

我试过了username@host.com:password @ http://localhost:8080/PortletName-portlet/api/jsonws/?serviceClassName=com.service.NameServiceUtil&serviceMethodName=getMyNames&serviceParameters=[userid]&userid=1

它不起作用!

我已确定在portal-ext.properties中添加了以下行并重新启动了服务器。

json.service.auth.token.enabled=true

我还应该做些什么才能通过Auth Token?有没有更好的方法可供我使用?

1 个答案:

答案 0 :(得分:2)

您实际上想要使用AuthVerifier。这是访问Liferay API并进行身份验证的最佳方法。它类似于自动记录概念。

查看https://dev.liferay.com/es/discover/deployment/-/knowledge_base/7-0/authentication-verifiers并查看源代码中的PortalSessionAuthVerifier类。

这个概念非常简单。读取请求对象并确定用户是谁。执行自定义身份验证并使用用户标识返回身份验证结果。