...
The examples below use the API to authenticate to . Before using the API, you will need to install the client libraries for your language. frevvo offers Java and .NET client libraries. The examples below use the Java client libraries; the .NET versions are very similar. Click here for instructions on installing the Java client library.===
Authentication & Session Management
...
In order to automatically integrate with frevvo , your web application will first need to establish a session using the frevvo API API. This is done by using the '''com.frevvo.forms.client.FormsService''' class class and by providing proper credentials to authenticate.
In most cases, you will want to use the loginAs() method available in V4.1.1 and higher. loginAs() allows you to login to frevvo as any existing tenant user provided you pass in the tenant admin's user and password credentials. This is convenient when you want login to frevvo using the same user that is logged into your application without having to know their password.====
Login as an existing user
...
The following snippet shows how to login as a tenant user. This usage assumes that the user has already been created in the tenant.<pre>
Code Block |
---|
... |
...
// tenantAdminUserId must be specified as adminUserId@tenantName |
...
FormsService s = new FormsService(protocol, host, port, null); |
...
s.loginAs(userId, tenantAdminUserId, tenantAdminPassword); |
...
... |
</pre>* protocol
- protocol is one of http or https
...
- host is the frevvo server host name
...
- port is the port on which frevvo is running
...
- userId is the tenant user's id
...
- tenantAdminUserId is the user id of the tenant admin user specified using the syntax adminUserId@tenantName
...
- tenantAdminPassword is the password of the tenant admin user
...
Auto-create users in a tenant
...
can also automatically create users in your tenant if you created it with [[V4_Tenants_Page#Delegating_Security_Manager | the Delegating Security Manager]].<pre>
Code Block |
---|
... |
...
List<String> roles = Collections.singletonList("manager"); |
...
FormsService s = new FormsService(getProtocol(), getHost(), getPort(), null); |
...
// tenantAdminUserId must be specified as adminUserId@tenantName |
...
s.loginAs(userId, tenantAdminUserId, tenantAdminPassword, true, roles, firstName, lastName, email, null); |
...
... |
</pre>
This will log you in as the specified userId. If a user with that ID does not exist, the user will be automatically created. The user will have any existing roles as well as the role "manager". If you do not want to specify any roles, you may pass in null. Of course, you can pass in a List with as many roles as you want.
If you want frevvo to to auto create a new user that can design forms, you need to pass in the '''frevvo.Designer''' role role when calling loginAs().
<span style="font-weight:bold;background-color:#ffce7b">This This is typically not required unless you are an OEM customer embedding the frevvo Designer in your product.</span>
For For instance:<pre>
Code Block |
---|
... |
...
List<String> roles = Collections.singletonList("frevvo.Designer"); |
...
FormsService s = new FormsService(protocol, host, port, null); |
...
s.loginAs(userId, tenantAdminUserId, tenantAdminPassword, true, roles, firstName, lastName, email, null); |
...
... |
...
JSP Usage
...
Your JSP page code will look very similar to the above. An important thing to note is that the FormsService instance is state-full and the same instance needs to be used throughout the session (this is specially the case when rendering form urls in the browser since an API key is automatically appended and bound to the FormsService session - as soon as you logout() the API key becomes invalid). Typically, in a web application context, the FormsService instance is stored in the HTTP session that the user has with your web application.<pre>
Code Block |
---|
<%@ page import="java.util.*,com.frevvo.forms.client.*,com.frevvo.forms.client.util.*" %> |
...
FormsService service = (FormsService) session.getAttribute ( "frevvo.forms.service" ); |
...
if (service == null) { |
...
service = new FormsService("http", "localhost", 8082, null); |
...
service.loginAs (request.getParameter( "username" ), |
...
tenantAdminUserId, tenantAdminPassword, true, null, |
...
request.getParameter( "firstname" ), |
...
request.getParameter( "lastname" ), |
...
request.getParameter( "email" ), null); |
...
} session.setAttribute ("frevvo.forms.service", service); |
...
==Embed a form or workflow with authentication==
<div style="font-weight:bold;background-color:#63ffc7">[[Image:Lightbulb.png]] Make sure you have read and understood the documentation on [[V4_Using_Forms#Making_a_Form_Public | making forms and flows public]].</div>
Now that you have logged in, you must use the FormsService created above to get an embed URL for the form/flow that you want to embed.
<pre>
FormTypeEntry ftEntry = (FormTypeEntry) service.getEntry(
service.getEntryURL(FormTypeEntry.class, "_iAMawOa4Ed-TkpzYF5hpcQ!_MOrvYeV9Ed-6Ft_YAwCXMQ!designer"),
FormTypeEntry.class);
String formUrl = ftEntry.getFormTypeEmbedLink(null).getHref();
</pre>
...