@expose("<STR_LIT>", methods=["<STR_LIT:POST>"])<EOL><INDENT>@safe<EOL>def login(self):<DEDENT>
if not request.is_json:<EOL><INDENT>return self.response_400(message="<STR_LIT>")<EOL><DEDENT>username = request.json.get(API_SECURITY_USERNAME_KEY, None)<EOL>password = request.json.get(API_SECURITY_PASSWORD_KEY, None)<EOL>provider = request.json.get(API_SECURITY_PROVIDER_KEY, None)<EOL>refresh = request.json.get(API_SECURITY_REFRESH_KEY, False)<EOL>if not username or not password or not provider:<EOL><INDENT>return self.response_400(message="<STR_LIT>")<EOL><DEDENT>if provider == API_SECURITY_PROVIDER_DB:<EOL><INDENT>user = self.appbuilder.sm.auth_user_db(username, password)<EOL><DEDENT>elif provider == API_SECURITY_PROVIDER_LDAP:<EOL><INDENT>user = self.appbuilder.sm.auth_user_ldap(username, password)<EOL><DEDENT>else:<EOL><INDENT>return self.response_400(<EOL>message="<STR_LIT>".format(provider)<EOL>)<EOL><DEDENT>if not user:<EOL><INDENT>return self.response_401()<EOL><DEDENT>resp = dict()<EOL>resp[API_SECURITY_ACCESS_TOKEN_KEY] = create_access_token(<EOL>identity=user.id, fresh=True<EOL>)<EOL>if refresh:<EOL><INDENT>resp[API_SECURITY_REFRESH_TOKEN_KEY] = create_refresh_token(<EOL>identity=user.id<EOL>)<EOL><DEDENT>return self.response(<NUM_LIT:200>, **resp)<EOL>
Login endpoint for the API returns a JWT and optionally a refresh token
        ---
        post:
          requestBody:
            required: true
            content:
              application/json:
                schema:
                  type: object
                  properties:
                    username:
                      type: string
                    password:
                      type: string
                    provider:
                      type: string
                      enum:
                      - db
                      - ldap
                    refresh:
                      type: boolean
          responses:
            200:
              description: Authentication Successful
              content:
                application/json:
                  schema:
                    type: object
                    properties:
                      access_token:
                        type: string
                      refresh_token:
                        type: string
            400:
              $ref: '#/components/responses/400'
            401:
              $ref: '#/components/responses/401'
            500:
              $ref: '#/components/responses/500'