{
  "openapi": "3.0.0",
  "info": {
    "description": "This service handles authentication and validation of identity. A username and password can be exchanged for a [JWT](http://jwt.io) token to gain authorization to other services, including identity information on this service.\n",
    "title": "Authentication API",
    "version": "1.9.1"
  },
  "tags": [
    {
      "description": "Need to authenticate as a person? Forgot your password? You're in the right place.",
      "name": "Authentication"
    },
    {
      "description": "Create and update a person's profile",
      "name": "People"
    }
  ],
  "servers": [
    {
      "url": "https://api.login.wheniwork.com",
      "description": "Production"
    }
  ],
  "paths": {
    "/login": {
      "post": {
        "summary": "Login",
        "description": "This endpoint logs you into a Person's account. It allows you to exchange an email and password for a token.\n",
        "tags": [
          "Authentication"
        ],
        "requestBody": {
          "$ref": "#/components/requestBodies/LoginRequest"
        },
        "responses": {
          "200": {
            "description": "Login",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "person": {
                      "$ref": "#/components/schemas/PersonWithToken"
                    },
                    "token": {
                      "$ref": "#/components/schemas/Token"
                    }
                  },
                  "required": [
                    "token",
                    "person"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/people": {
      "post": {
        "summary": "Create Person",
        "description": "",
        "tags": [
          "People"
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/Person"
                  },
                  {
                    "properties": {
                      "password": {
                        "type": "string"
                      }
                    },
                    "type": "object"
                  }
                ],
                "example": {
                  "email": "king@camelot.com",
                  "firstName": "King",
                  "lastName": "Arthur",
                  "password": "ilovewheniwork",
                  "phone": "+16515558899"
                },
                "required": [
                  "firstName",
                  "email",
                  "password"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PersonWithToken"
                }
              }
            }
          }
        }
      },
      "put": {
        "summary": "Update Person",
        "description": "Update the currently authenticated user.",
        "tags": [
          "People"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/authorization"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/Person"
                  }
                ],
                "example": {
                  "firstName": "King",
                  "lastName": "Arthur"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/Person"
          }
        }
      }
    },
    "/people/me": {
      "get": {
        "summary": "Get Person",
        "description": "Retrieves the `Person` object for the currently authenticated user.",
        "tags": [
          "People"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/authorization"
          }
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/Person"
          }
        }
      }
    },
    "/people/password": {
      "post": {
        "summary": "Update Password",
        "description": "Update the current `Person`'s password",
        "tags": [
          "People"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/authorization"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "example": {
                  "newPassword": "ireallylovewheniwork",
                  "oldPassword": "ilovewheniwork"
                },
                "type": "object",
                "properties": {
                  "newPassword": {
                    "type": "string"
                  },
                  "oldPassword": {
                    "type": "string"
                  }
                },
                "required": [
                  "oldPassword",
                  "newPassword"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/Person"
          }
        }
      }
    },
    "/refresh": {
      "post": {
        "summary": "Refresh Token",
        "description": "Will return a new token that can be used in place of your current token.",
        "tags": [
          "Authentication"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/authorization"
          }
        ],
        "responses": {
          "200": {
            "description": "Ok",
            "content": {
              "application/json": {
                "schema": {
                  "token": {
                    "$ref": "#/components/schemas/Token"
                  },
                  "required": [
                    "token"
                  ],
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "parameters": {
      "ssoProvider": {
        "in": "path",
        "name": "provider",
        "required": true,
        "schema": {
          "type": "string",
          "enum": [
            "google",
            "square",
            "quickbooks"
          ]
        }
      },
      "adminAuthorization": {
        "in": "header",
        "name": "Authorization",
        "required": true,
        "schema": {
          "type": "string"
        },
        "example": "abc123"
      },
      "authorization": {
        "in": "header",
        "name": "Authorization",
        "required": true,
        "example": "xxxxx.yyyyy.zzzzz",
        "schema": {
          "type": "string"
        }
      },
      "personId": {
        "in": "path",
        "name": "id",
        "description": "The ID of the person to lookup",
        "required": true,
        "type": "string",
        "example": 12347
      },
      "tmpTokenCode": {
        "description": "The short-lived code of the temp token",
        "in": "path",
        "name": "code",
        "required": true,
        "example": "ABC12",
        "schema": {
          "type": "string"
        }
      }
    },
    "requestBodies": {
      "LoginRequest": {
        "description": "Credentials for the person to login.",
        "content": {
          "application/json": {
            "schema": {
              "example": {
                "email": "king@camelot.com",
                "password": "ilovewheniwork"
              },
              "properties": {
                "email": {
                  "description": "The email address for the person",
                  "type": "string"
                },
                "password": {
                  "description": "The password for the person",
                  "type": "string"
                }
              },
              "required": [
                "email",
                "password"
              ],
              "type": "object"
            }
          }
        }
      }
    },
    "responses": {
      "PersonAndToken": {
        "description": "Ok",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "person": {
                  "$ref": "#/components/schemas/Person"
                },
                "token": {
                  "$ref": "#/components/schemas/Token"
                }
              },
              "required": [
                "person",
                "token"
              ]
            }
          }
        }
      },
      "PersonWithToken": {
        "description": "Ok",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "person": {
                  "$ref": "#/components/schemas/PersonWithToken"
                }
              },
              "required": [
                "person"
              ]
            }
          }
        }
      },
      "Person": {
        "description": "Ok",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "person": {
                  "$ref": "#/components/schemas/Person"
                }
              },
              "required": [
                "person"
              ]
            }
          }
        }
      }
    },
    "schemas": {
      "Avatar": {
        "properties": {
          "large": {
            "example": "https://avatar.wheniwork.com//large",
            "type": "string"
          },
          "medium": {
            "example": "https://avatar.wheniwork.com//medium",
            "type": "string"
          },
          "small": {
            "example": "https://avatar.wheniwork.com//small",
            "type": "string"
          }
        },
        "readOnly": true,
        "type": "object"
      },
      "Person": {
        "type": "object",
        "properties": {
          "avatar": {
            "$ref": "#/components/schemas/Avatar"
          },
          "email": {
            "type": "string"
          },
          "firstName": {
            "type": "string"
          },
          "id": {
            "readOnly": true,
            "type": "string"
          },
          "lastName": {
            "type": "string"
          },
          "phone": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "firstName",
          "email"
        ],
        "example": {
          "email": "king@camelot.com",
          "firstName": "King",
          "id": "12347",
          "lastName": "Arthur",
          "phone": "+16515558899"
        }
      },
      "PersonWithToken": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Person"
          },
          {
            "properties": {
              "token": {
                "$ref": "#/components/schemas/Token"
              }
            },
            "required": [
              "token"
            ],
            "type": "object"
          }
        ]
      },
      "SSOUrl": {
        "example": {
          "url": null
        },
        "properties": {
          "url": {
            "description": "The URL where the browser should redirect",
            "type": "string"
          }
        },
        "required": [
          "url"
        ],
        "type": "object"
      },
      "TmpToken": {
        "example": {
          "expiresAt": "2017-01-01T12:12:12.000Z",
          "id": "ABC12",
          "token": "xxxx.yyyyy.zzzzz",
          "used": true
        },
        "properties": {
          "expiresAt": {
            "type": "string"
          },
          "id": {
            "type": "string"
          },
          "token": {
            "type": "string"
          },
          "used": {
            "type": "boolean"
          }
        },
        "type": "object"
      },
      "Token": {
        "example": "xxxxx.yyyyy.zzzzz",
        "type": "string"
      }
    }
  }
}