github.com/iron-io/functions@v0.0.0-20180820112432-d59d7d1c40b2/examples/jwt/README.md (about)

     1  # Quick Example for JWT Authentication
     2  
     3  This example will show you how to test and deploy a function with JWT Authentication.
     4  
     5  ```sh
     6  # create your func.yaml file
     7  fn init <YOUR_DOCKERHUB_USERNAME>/<REPO NAME>
     8  
     9  # Add 
    10  # jwt_key: <Your JWT signing key>
    11  # to your func.yml
    12  
    13  # build the function
    14  fn build
    15  # test it
    16  fn run
    17  # push it to Docker Hub
    18  fn push
    19  # Create a route to this function on IronFunctions
    20  fn routes create myapp /jwt
    21  
    22  
    23  ```
    24  
    25  If you are going to add jwt authentication to an existing function,
    26  you can simply add `jwt_key` to your func.yml, and update your route
    27  using fn tool update command.
    28  
    29  Now you can call your function on IronFunctions:
    30  
    31  ```sh
    32  # Get token for authentication
    33  fn routes token myapp /jwt
    34  # The token expiration time is 1 hour by default. You can also specify the expiration time explicitly.
    35  # Below example set the token expiration time at 500 seconds :
    36  fn routes token myapp /jwt 500
    37  
    38  # The response will include a token :
    39  # {
    40  #        "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MDgwNTcwNTEsImlhdCI6MTUwODA1MzQ1MX0.3c_xUaleCdHy_fdU9zFB50j3hqwYWgPZ-EkTXV3VWag"
    41  # }
    42  
    43  # Now, you can access your app with a token :
    44  curl  -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MDgwNTcwNTEsImlhdCI6MTUwODA1MzQ1MX0.3c_xUaleCdHy_fdU9zFB50j3hqwYWgPZ-EkTXV3VWag' http://localhost:8080/r/myapp/jwt
    45  
    46  # or use fn tool
    47  # This will automatically generate a token and make function call :
    48  fn routes call myapp /jwt
    49  
    50  ```
    51  
    52  __important__: Please note that enabling Jwt authentication will require you to authenticate each time you try to call your function.
    53  You won't be able to call your function without a token.
    54  
    55  ## Dependencies
    56  
    57  Be sure your dependencies are in the `vendor/` directory.
    58