Skip to content

Instantly share code, notes, and snippets.

@Tmeister
Created February 17, 2025 20:10
Show Gist options
  • Select an option

  • Save Tmeister/7750f7b868368d28d16608309f2e00f7 to your computer and use it in GitHub Desktop.

Select an option

Save Tmeister/7750f7b868368d28d16608309f2e00f7 to your computer and use it in GitHub Desktop.
{
"info": {
"name": "jwt-auth-pro",
"description": "",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "me",
"event": [
{
"listen": "test",
"script": {
"exec": [
"test(\"should get user data successfully\", function() {",
" expect(res.getStatus()).to.equal(200);",
"});",
"",
"test(\"response should contain user identification\", function() {",
" const data = res.getBody();",
" expect(data).to.have.property('id');",
" expect(data.id).to.be.a('number');",
" expect(data).to.have.property('name');",
"});",
"",
"test(\"response should contain user link\", function() {",
" const data = res.getBody();",
" expect(data).to.have.property('link');",
" expect(data.link).to.be.a('string');",
"});",
"",
"test(\"response headers should be correct\", function() {",
" expect(res.getHeader('content-type')).to.include('application/json');",
"});"
]
}
}
],
"request": {
"method": "GET",
"header": [],
"auth": {
"type": "bearer",
"bearer": {
"key": "token",
"value": "{{token}}",
"type": "string"
}
},
"description": "",
"url": {
"raw": "{{baseURL}}/wp-json/wp/v2/users/me",
"protocol": "",
"host": [
"{{baseURL}}"
],
"path": [
"wp-json",
"wp",
"v2",
"users",
"me"
],
"query": [],
"variable": []
}
}
},
{
"name": "refresh",
"event": [
{
"listen": "test",
"script": {
"exec": [
"test(\"should refresh token successfully\", function() {",
" expect(res.getStatus()).to.equal(200);",
"});",
"",
"test(\"response should contain valid access token\", function() {",
" const data = res.getBody();",
" expect(data).to.have.property('access_token');",
" expect(data.access_token).to.be.a('string').and.not.empty;",
" // JWT format validation (header.payload.signature)",
" expect(data.access_token.split('.')).to.have.lengthOf(3);",
"});",
"",
"test(\"response should contain valid refresh token\", function() {",
" const data = res.getBody();",
" expect(data).to.have.property('refresh_token');",
" expect(data.refresh_token).to.be.a('string').and.not.empty;",
" // Refresh token should be different from the one used to make the request",
" expect(data.refresh_token).to.not.equal('{{refresh_token}}');",
"});",
"",
"test(\"response should contain correct token type\", function() {",
" const data = res.getBody();",
" expect(data).to.have.property('token_type');",
" expect(data.token_type).to.equal('Bearer');",
"});",
"",
"test(\"response should contain valid expiration time\", function() {",
" const data = res.getBody();",
" expect(data).to.have.property('expires_in');",
" expect(data.expires_in).to.be.a('number');",
"});",
"",
"test(\"response headers should be correct\", function() {",
" expect(res.getHeader('content-type')).to.include('application/json');",
"});"
]
}
}
],
"request": {
"method": "POST",
"header": [],
"auth": null,
"description": "",
"url": {
"raw": "{{baseURL}}/wp-json/jwt-auth/v1/token/refresh",
"protocol": "",
"host": [
"{{baseURL}}"
],
"path": [
"wp-json",
"jwt-auth",
"v1",
"token",
"refresh"
],
"query": [],
"variable": []
},
"body": {
"mode": "raw",
"raw": "{\n \"refresh_token\": \"{{refresh_token}}\"\n}",
"options": {
"raw": {
"language": "json"
}
}
}
}
},
{
"name": "token",
"event": [
{
"listen": "test",
"script": {
"exec": [
"test(\"should be able to get a token\", function() {",
" const data = res.getBody();",
" expect(res.getStatus()).to.equal(200);",
"});",
"",
"test(\"response should contain valid JWT token\", function() {",
" const data = res.getBody();",
" expect(data).to.have.property('token');",
" expect(data.token).to.be.a('string').and.not.empty;",
" // JWT format validation (header.payload.signature)",
" expect(data.token.split('.')).to.have.lengthOf(3);",
"});",
"",
"test(\"response should contain valid refresh token\", function() {",
" const data = res.getBody();",
" expect(data).to.have.property('refresh_token');",
" expect(data.refresh_token).to.be.a('string').and.not.empty;",
"});",
"",
"test(\"response should contain user data\", function() {",
" const data = res.getBody();",
" expect(data).to.have.property('user_email');",
" expect(data).to.have.property('user_nicename');",
" expect(data).to.have.property('user_display_name');",
" expect(data.user_email).to.be.a('string').and.not.empty;",
" expect(data.user_nicename).to.be.a('string').and.not.empty;",
" expect(data.user_display_name).to.be.a('string').and.not.empty;",
"});",
"",
"test(\"response headers should be correct\", function() {",
" expect(res.getHeader('content-type')).to.include('application/json');",
"});"
]
}
}
],
"request": {
"method": "POST",
"header": [],
"auth": null,
"description": "",
"url": {
"raw": "{{baseURL}}/wp-json/jwt-auth/v1/token",
"protocol": "",
"host": [
"{{baseURL}}"
],
"path": [
"wp-json",
"jwt-auth",
"v1",
"token"
],
"query": [],
"variable": []
},
"body": {
"mode": "raw",
"raw": "{\n \"username\": \"{{username}}\",\n \"password\": \"{{password}}\"\n}",
"options": {
"raw": {
"language": "json"
}
}
}
}
},
{
"name": "validate",
"event": [
{
"listen": "test",
"script": {
"exec": [
"test(\"should validate token successfully\", function() {",
" expect(res.getStatus()).to.equal(200);",
"});",
"",
"test(\"response should indicate valid token\", function() {",
" const data = res.getBody();",
" expect(data).to.have.property('code');",
" expect(data.code).to.equal('jwt_auth_valid_token');",
"});",
"",
"test(\"response should have correct status in data\", function() {",
" const data = res.getBody();",
" expect(data).to.have.property('data');",
" expect(data.data).to.have.property('status');",
" expect(data.data.status).to.equal(200);",
"});",
"",
"test(\"response headers should be correct\", function() {",
" expect(res.getHeader('content-type')).to.include('application/json');",
"});"
]
}
}
],
"request": {
"method": "POST",
"header": [],
"auth": {
"type": "bearer",
"bearer": {
"key": "token",
"value": "{{token}}",
"type": "string"
}
},
"description": "",
"url": {
"raw": "{{baseURL}}/wp-json/jwt-auth/v1/token/validate",
"protocol": "",
"host": [
"{{baseURL}}"
],
"path": [
"wp-json",
"jwt-auth",
"v1",
"token",
"validate"
],
"query": [],
"variable": []
}
}
},
{
"name": "bruno",
"event": []
}
],
"variable": [
{
"key": "baseURL",
"value": "",
"type": "default"
},
{
"key": "token",
"value": "",
"type": "default"
},
{
"key": "refresh_token",
"value": "",
"type": "default"
},
{
"key": "username",
"value": "",
"type": "default"
},
{
"key": "password",
"value": "",
"type": "default"
},
{
"key": "API_KEY",
"value": "",
"type": "default"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment