Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add admin login auth flow #112

Merged
merged 2 commits into from
Jan 17, 2024
Merged

Conversation

xixas
Copy link
Collaborator

@xixas xixas commented Jan 11, 2024

Can provide mutation to login user to recieve API token.
Fetch Notifications API is now behind API Guard. So need to use the login token as AUthorization Header

  1. Use the graphQL playground to test.

Request Mutation: Add mutation and return data which you want.

mutation {
  login(loginUserInput: {
    username: "admin",
    password: "admin@123"
  }) {
    token
    user
  }
}

Or in postman
CURL

curl 'http://localhost:3000/graphql' -H 'Accept-Encoding: gzip, deflate, br' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Connection: keep-alive' -H 'DNT: 1' -H 'Origin: http://localhost:3000' --data-binary '{"query":"mutation login($input: LoginUserInput!){\n  login(loginUserInput: $input) {\n    token\n    user\n  }\n}\n","variables":{"input":{"username":"admin2","password":"admin@123"}}}' --compressed

Responses

  1. Invalid Credentials
{
  "errors": [
    {
      "message": "Invalid username or password",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "login"
      ],
      "extensions": {
        "code": "UNAUTHENTICATED",
        "stacktrace": [
          "UnauthorizedException: Invalid username or password",
          "    at LocalStrategy.validate (/home/vikas/work/projects/osmo-notify/apps/api/src/modules/auth/strategies/local.strategy.ts:19:13)",
          "    at processTicksAndRejections (node:internal/process/task_queues:95:5)",
          "    at LocalStrategy.callback [as _verify] (/home/vikas/work/projects/osmo-notify/apps/api/node_modules/@nestjs/passport/dist/passport/passport.strategy.js:11:44)"
        ],
        "originalError": {
          "message": "Invalid username or password",
          "error": "Unauthorized",
          "statusCode": 401
        }
      }
    }
  ],
  "data": null
}
  1. Valid Credentials Request
{
  "data": {
    "login": {
      "token": "osmo-notify-test-key",
      "user": "admin"
    }
  }
}
  1. Bad Request
{
  "error": {
    "errors": [
      {
        "message": "Field \"LoginUserInput.password\" of required type \"String!\" was not provided.",
        "locations": [
          {
            "line": 2,
            "column": 25
          }
        ],
        "extensions": {
          "code": "GRAPHQL_VALIDATION_FAILED",
          "stacktrace": [
            "GraphQLError: Field \"LoginUserInput.password\" of required type \"String!\" was not provided.",
            "    at ObjectValue (/home/vikas/work/projects/osmo-notify/apps/api/node_modules/graphql/validation/rules/ValuesOfCorrectTypeRule.js:64:13)",
            "    at Object.enter (/home/vikas/work/projects/osmo-notify/apps/api/node_modules/graphql/language/visitor.js:301:32)",
            "    at Object.enter (/home/vikas/work/projects/osmo-notify/apps/api/node_modules/graphql/utilities/TypeInfo.js:391:27)",
            "    at visit (/home/vikas/work/projects/osmo-notify/apps/api/node_modules/graphql/language/visitor.js:197:21)",
            "    at validate (/home/vikas/work/projects/osmo-notify/apps/api/node_modules/graphql/validation/validate.js:91:24)",
            "    at processGraphQLRequest (/home/vikas/work/projects/osmo-notify/apps/api/node_modules/@apollo/server/src/requestPipeline.ts:246:38)",
            "    at processTicksAndRejections (node:internal/process/task_queues:95:5)",
            "    at internalExecuteOperation (/home/vikas/work/projects/osmo-notify/apps/api/node_modules/@apollo/server/src/ApolloServer.ts:1309:12)",
            "    at runHttpQuery (/home/vikas/work/projects/osmo-notify/apps/api/node_modules/@apollo/server/src/runHttpQuery.ts:232:27)",
            "    at runPotentiallyBatchedHttpQuery (/home/vikas/work/projects/osmo-notify/apps/api/node_modules/@apollo/server/src/httpBatching.ts:85:12)"
          ]
        }
      }
    ]
  }
}

@ghost ghost mentioned this pull request Jan 11, 2024
@osm-vishnukyatannawar osm-vishnukyatannawar merged commit fa1f339 into main Jan 17, 2024
8 checks passed
@osm-vishnukyatannawar osm-vishnukyatannawar deleted the feat/admin-login branch January 17, 2024 05:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants