GOVX Connect enables access to users and verification status through a JavaScript SDK.
Basic Setup
<script type="text/javascript">
window.govxInit = function() {
GOVX.init({
clientId: '{client-id}'
})
}
</script>
<script async defer src="https://govxconnect.com/sdk.js"></script>
Advanced Setup
This section will go over several advanced setup options.
Changing SDK location
By default the SDK is pulled from https://www.govxconnect.com/sdk.{hash}.js, however, for QA purposes, we want to test the latest files. To do so add a data-sdk-js attribute to the script tag for loading the SDK.
Example
<script async defer src="https://staging.govxconnect.com/sdk.js" data-sdk-js="https://staging.govxconnect.com/sdk.d196dd412355f8a408c0.js"></script>
The latest file can be found by opening the sdk.js directly in the browser and copy/pasting the version.
Override settings
The default settings can be overridden by adding a window.__GOVX__ object before the script is loaded. This will change the settings then remove the __GOVX__ object once loaded.
Example
window.__GOVX__ = {
settings: {
AuthOrigin: 'https://staging-auth.govx.com',
DataOrigin: 'https://staging-auth.govx.com',
TrackingOrigin: 'https://staging-auth.govx.com'
}
}
SDK
1. Init
The GOVX.init() method is used to initialize the SDK, this should be called before any other methods.
GOVX.init(params)
Parameters
Name | Type | Description |
---|---|---|
clientId | string | Client ID associated with listing. |
Example
GOVX.init({
clientId: '{client-id}'
})
2. Check Status
The GOVX.getStatus() method checks the current status of the logged in user as well as their verification summary based on the current client/campaign. If the user is logged in and has granted data access to the client, the response will contain "auth" which contains the userId and a token to fetch user data.
GOVX.getStatus(params, function(response){})
Parameters
Name | Type | Description |
---|---|---|
campaign | string | The name of the campaign (if applicable) |
Response
Name | Type | Description |
---|---|---|
status | login_status | The login status of the user. |
verification | verification_status | The verification status of the user. |
auth | auth_data | Authorization data for the user, this will only be available if status is "Authorized". |
login_status
Name | Description |
---|---|
Authorized | The user is logged in and has granted data access to the client. |
Not_Authorized | The user is logged in but has not granted data access to the client. |
Unknown | The user has either not logged in or it can not be determined their current status. |
verification_status
Name | Description |
---|---|
Approved | The user has at least one approved occupation for the client. |
Pending | The user has at least one pending occupation for the client. |
Unknown | The user either has no occupations for the client or the current status can not be determined. |
auth_data
Name | Type | Description |
---|---|---|
accessToken | string | The access token used to get additional information about the user. Contains the scope provided during setup. |
expiresIn | unix timestamp | The date the access token will expire and need to be re-issued. |
userId | string | The currently logged in User ID. |
Example Request
GOVX.getStatus({}, function(response) {
if (response.status === 'Authorized') {
// The user is logged in and authenticated app, the response will contain auth data for fetching user information as well as the verification status for your app.
if (response.verification === 'Approved') {
// The user is in an accepted occupation.
} else if (response.verification === 'Pending') {
// The user is in the process of being validated for an accepted occupation.
} else {
//The user has no outstanding verification requests for an accepted occupation.
}
} else if (response.status === 'Not_Authorized') {
// The user is logged in but has not yet authorized app. Calling login will require the user to approve / deny app.
// If the user has no pending valid verification requests for app, they will be required to re-login and verify before approve / deny.
} else {
// The user is not known to be logged in, they'll need to fully log in / go through verification process.
}
})
Example Response
{
"status": "Authorized",
"verification": "Approved",
"auth": {
"accessToken": "{access-token}",
"expiresIn": "{unix-timestamp}",
"signature": "{signature}",
"userId": "{user_id}"
}
}
3. Login
The GOVX.login() method will attempt to login a user and grant access to the client. The user will be pushed through GOVX verification flow.
GOVX.login({}, function(response){ })
Parameters
Name | Type | Description |
---|---|---|
campaign | string | Uses the specified campaign for the login process. |
goTo | string | "login" or "register" to direct the user to the cooresponding path. |
Response
Name | Type | Description |
---|---|---|
status | login_status | The login status of the user. |
verification | verification_status | The verification status of the user. |
auth | auth_data | Auth data for the user. |
login_data
Name | Type | Description |
---|---|---|
timestamp | unix timestamp | Timestamp of when the response was created. |
Example
GOVX.login({ campaign: '{campaign}', function(response) {
if (response.status === 'Authorized') {
//The user has logged in and granted access, the login property of the response can be validated to ensure the user logged in as requested.
} else {
//user did not login or grant access.
}
}})
4. Logout
The GOVX.logout() method logs a user out of the current client.
GOVX.logout(function(response){
//the user is logged out
})
5. API
The GOVX.api() method uses the current auth token to request data regarding the user.
GOVX.api({ }, function(response){ })
Parameters
Name | Type | Description |
---|---|---|
Response
Same as oauth solution. See: https://support.govxinc.com/hc/en-us/articles/360028760851
Example
GOVX.api({}, function(response) {
var profile = response.userProfile;
/*
{
"id": "ecffdd04-bb49-4e8a-b561-2737238ac31d",
"username": "test@govx.com",
"email": "test@govx.com",
"firstName": "Test",
"lastName": "McTesting"
}
*/
})
Comments
0 comments
Please sign in to leave a comment.