Login

Overview

Mutation inviteEntityToLogin can be used to create accounts for entities (eg. individual, internal and company ) to login to an app created in CoverGo system. Successful request of mutation inviteEntityToLogin will create a login for the entity.

Sometimes you may have multiple front end applications (FE Apps). In CoverGo system, different FE Apps are identified by clientId. For information on logging in to different FE Apps, please refer to Access to different apps.

Query Examples

Invite Entity to Login

mutation inviteEntityToLogin (
  $clientId:String!, 
  $input:inviteEntityInput!
) {
  inviteEntityToLogin(
    clientId: $clientId, 
    input:$input
  ){
    createdStatus { id } 
    status 
    errors
  }
}

Input:

{
  "clientId": "BrokerPortal",
  "input": {
    "entityId": "655bd112-61a6-4002-81b3-96012ac92624",
    "email": "[email protected]"
  }
}

Example Result:

{
  "data": {
    "inviteEntityToLogin": {
      "createdStatus": {
        "id": "60ab0c5b1b1e9f83465e5243"
      },
      "status": "success",
      "errors": null
    }
  }
}

Create New Password

An email will be sent to the email specified in mutation inviteEntityToLogin (in above example, it is [email protected]) upon success login creation. The mail should include a link for the entity to create a new password.

mutation newPassword(
  $tenantId:String! 
  $loginId:String!
  $code:String!
  $password:String!
) {
  resetPassword(
    tenantId: $tenantId
    loginId: $loginId
    code: $code
    password: $password
  ) {
    status errors errors_2 { code message }
  }
}

Input:

{
  "tenantId": "demo_uat",
  "loginId": "60ab0c5b1b1e9f83465e5243",
  "code": "<CODE_IN_URL>",
  "password": "MyNewPassword"
}

Tips:

The code sent by the email will be url encoded. We need to decoded it before using it in <CODE_IN_URL>.

Example Result:

{
  "data": {
    "resetPassword": {
      "status": "success",
      "errors": null,
      "errors_2": null
    }
  }
}

Forget Password

Mutation forgotPassword can be used to reset password of a login.

mutation forgotPassword (
  $tenantId:String!
  $forgotPasswordInput:forgotPasswordInput!
) {
  forgotPassword(
    tenantId: $tenantId
    forgotPasswordInput: $forgotPasswordInput
  ){
    status errors errors_2 {code message}
  }
}

Input:

{
  "tenantId": "demo_uat",
  "forgotPasswordInput": {
    "clientId": "BrokerPortal",
    "email": "[email protected]",
    "username": "[email protected]"
  }
}

Example Result:

{
  "data": {
    "forgotPassword": {
      "status": "success",
      "errors": null,
      "errors_2": null
    }
  }
}

An email similar to that of inviteEntityToLogin will be sent to the email address specified in the query (ie. [email protected] in the above example). Mutation resetPassword can then be used to reset the password.

Access to Different FE Apps

For example, your company two FE Apps, one for agents (AgentPortal) and the other one for brokers (BrokerPortal). Access to different applications of an entity can be granted by adding targettedPermission to the login of the entity.

No access to AgentPortal

The login we created above only have access to the BrokerPortal. If we try to login to the AgentPortal, it will fail:

query login {
  token_2(
    tenantId: "demo_uat",
    clientId: "AgentPortal",
    username: "[email protected]",
    password: "MyNewPassword"
  ){
    accessToken
    refreshToken
    error
  }
}

Example Result:

{
  "data": {
    "token_2": {
      "accessToken": null,
      "refreshToken": null,
      "error": "invalid_client"
    }
  }
}

If we try to look at the login, we see in targettedPermissions, there is only BrokerProtal in the targetIds under permission of type clientId:

query login($username:String!) {
  login(username:$username) {
    id
    targettedPermissions { 
      permission { id } 
      targetIds 
    }
  }
}

Input:

{
  "username": "[email protected]"
}

Example Result:

{
  "data": {
    "login": {
      "id": "6081039c052f07644d0c34bd",
      "targettedPermissions": [
        {
          "permission": {
            "id": "clientId"
          },
          "targetIds": [
            "BrokerPortal"
          ]
        }
      ]
    }
  }
}

Grant access to AgentPortal

To grant access to the AgentPortal for user "testinternal@covergo", the mutation addTargettedPermission could be used:

mutation grantAccessToLogin(
  $loginId:String!, 
  $input:addTargettedPermissionInput!
) {
  addTargettedPermission(
    loginId: $loginId
    addTargettedPermissionInput: $input
  ) {
    status errors
  }
}

Input:

{
  "loginId": "6081039c052f07644d0c34bd",
  "input": {
    "type": "clientId",
    "value": "AgentPortal"
  }
}

Example Result:

{
  "data": {
    "addTargettedPermission": {
      "status": "success",
      "errors": null
    }
  }
}

A targetted permission will be added to the login under the permission type clientId, as demostrated below:

query login($username:String!) {
  login(username:$username) {
    id
    targettedPermissions { 
      permission { id } 
      targetIds 
    }
  }
}

Input:

{
  "username": "[email protected]"
}

Example Result:

{
  "data": {
    "login": {
      "id": "6081039c052f07644d0c34bd",
      "targettedPermissions": [
        {
          "permission": {
            "id": "clientId"
          },
          "targetIds": [
            "BrokerPortal",
            "AgentPortal"
          ]
        }
      ]
    }
  }
}

Successful login to AgentPortal

Now the user can login to AgentPortal:

query login {
  token_2(
    tenantId: "demo_uat",
    clientId: "AgentPortal",
    username: "[email protected]",
    password: "MyNewPassword"
  ){
    accessToken
    refreshToken
    error
  }
}

Example Result:

{
  "data": {
    "token_2": {
      "accessToken": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE2MjIxODUyNjQsImV4cCI6MTYyMjI3MTY2NCwiaXNzIjoiaHR0cDovL2xvY2FsaG9zdDo2MDAwMCIsImF1ZCI6WyJodHRwOi8vbG9jYWxob3N0OjYwMDAwL3Jlc291cmNlcyIsImN1c3RvbV9wcm9maWxlIl0sImNsaWVudF9pZCI6IkFnZW50UG9ydGFsIiwic3ViIjoiNjBiMDc1ZjU3MTA2MWFkMzcxZTkzZTQ2IiwiYXV0aF90aW1lIjoxNjIyMTg1MjY0LCJpZHAiOiJsb2NhbCIsInRlbmFudElkIjoiZGVtb191YXQiLCJhcHBJZCI6IkFnZW50UG9ydGFsIiwiZW50aXR5SWQiOiI4MzU4ZDQ0ZC1lNWU4LTQ1NTAtYjk2My1mN2Y0NjYzZTM0YTAiLCJlbnRpdHlUeXBlIjoiaW50ZXJuYWwiLCJzY29wZSI6WyJjdXN0b21fcHJvZmlsZSIsIm9mZmxpbmVfYWNjZXNzIl0sImFtciI6WyJwd2QiXX0.xHRXravA85OrDRKsn1AUfK0P_dlkFEyqjT3wvxB86wjZ3n9efGMLmK2tt0gsMwgcDw3J6HTudoRP-oANbzHxSZK_JFQ4qLLsJNSiuIWk0N7LKzLkwPkXgyn3mFtRbr7K-FNE2YjfM0ajvjSL-YwYVdqxukGrpAi1xiX40LRNznXPMbEkrdpWZmjbn5WNE1QL2akFKStBLy_tquA_1xeuRcWcaKQqnSTW7w05fiQ0AphyWIS27OyEKA7NTL6QzyEVl_Z2llc2-7FwjblLgy-5B5f7xFiTHPSuiYPk0P8XoEalfxYL-ZDSSxHTRudHW-Q3ZSZOLXqL1dW72Irvig-sWg",
      "refreshToken": "d6777e4978f25b50579332f1b9e29fed140b563da64d892544dcd0371edf9537",
      "error": null
    }
  }
}