api

command
Version: v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2020 License: BSD-3-Clause Imports: 2 Imported by: 0

README

Gateway with a JWT

This recipe is a gateway with a service protected by a JWT.

Installation

  • Install Go
git clone https://github.com/project-flogo/microgateway
cd microgateway/activity/jwt/examples/api

Testing

Generate a JWT token using the below information: (You may use http://jwtbuilder.jamiekurtz.com/)

{
     "issuer": "Mashling",
     "audience": "www.mashling.io",
     "subject": "tempuser@mail.com",
     "id": "XX",
     "signingMethod": "HMAC"
}
{
     "key": "qwertyuiopasdfghjklzxcvbnm789101"
}

Note: The id in the above payload is the pet Id.

Start the gateway:

go run main.go

and test below scenario.

Token is Valid

Now run the following in a new terminal:

curl --request GET http://localhost:9096/pets -H "Authorization: Bearer <Access_Token>"

You should see the following response:

{
   "error":"JWT token is valid",
   "pet":{
      "category":{
         "id":0,
         "name":"string"
      },
      "id":4,
      "name":"gigigi",
      "photoUrls":[
         "string"
      ],
      "status":"available",
      "tags":[
         {
            "id":0,
            "name":"string"
         }
      ]
   }
}
Token Invalid

You should see the following response:

{
   "error":{
      "error":false,
      "errorMessage":"",
      "token":{
         "claims":null,
         "signature":"",
         "signingMethod":"",
         "header":null
      },
      "valid":false,
      "validationMessage":"signature is invalid"
   },
   "pet":null
}

Documentation

The Go Gopher

There is no documentation for this package.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL