Tutorial: Securing API Endpoints

Executing The API

The included ‘postman’ files show how to test the API. Here’s what a successful authentication request will return:

{
    "success": {
        "code": 200,
        "status": "OK",
        "message": "Success"
    },
    "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3R1c2VyIiwicGFzc3dvcmQiOiJ0ZXN0cGFzc3dvcmQiLCJvdGhlclRleHQiOiJUaGlzIGlzIGEgdGVzdCBtZXNzYWdlIiwiaWF0IjoxNDg3NDg5MTk3LCJleHAiOjE0ODc0OTAzOTcsImF1ZCI6Imh0dHA6Ly93d3cueW91cmFwaWV4cGVydC5jb20iLCJpc3MiOiJodHRwOi8vd3d3LnlvdXJhcGlleHBlcnQuY29tIiwic3ViIjoidGVzdHVzZXIifQ.zHdhNizV7L8dGi5tjVZJOxTFUn3ZxNDZ-UtnvHhS-7w",
    "expires_in": "1200",
    "refresh_token": "c9dddd3156f6b1666c1c52e9ff8c3404cde9562a297e3cc015db8c1c01666526529ab6435225c530"
}

When we submit the token to retrieve the user profile, a successful response will look like this:

{
    "success": {
        "code": 200,
        "status": "OK",
        "message": "Success"
    },
    "jwt": {
        "username": "testuser",
        "password": "testpassword",
        "otherText": "This is a test message",
        "iat": 1487489332,
        "exp": 1487490532,
        "aud": "http://www.yourapiexpert.com",
        "iss": "http://www.yourapiexpert.com",
        "sub": "testuser"
    }
}

 

In future articles we will build upon this example and increase our knowledge and confidence in designing and developing APIs.

Was This Helpful?
All of the content on this site is presented without advertiser support and is produced exclusively by me. If you find any of this information useful please consider it against the cost of a course or book.

I gladly accept donations of any amount which goes directly towards producing more quality content and videos for this site.

[wpedon id=119]

Pages: 1 2 3 4 5

Written by YourAPIExpert