Giter Club home page Giter Club logo

spring-rest-api-with-oauth2-and-jwt's Introduction

Spring REST API with OAuth2 and JWT

Para executar a aplicação

  • Maven
mnv clean spring-boot:run
  • Docker
mvn clean package docker:build
mvn docker:start

Informações adicionais

Exemplos de request

  • Gerar token de acesso:
curl [CLIENT-ID]:[CLIENT-SECRET]@localhost:8080/oauth/token -d grant_type=password -d username=[USER] -d password=[PASSWORD]
{
  "access_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiREEyRDUzMkQxQkVqd3RyZXNvdXJjZWlkIl0sInVzZXJfbmFtZSI6ImdhYnJpZWxjemFyIiwic2NvcGUiOlsicmVhZCIsIndyaXRlIl0sImV4cCI6MTcyNzMwNTQ3OCwiYXV0aG9yaXRpZXMiOlsiUk9MRV9VU0VSIl0sImp0aSI6ImY4MTJkYzBlLWZiZmItNDQ1My04ZDI2LTY5NmM2NWQ0MzA5ZiIsImNsaWVudF9pZCI6InNwcmluZy1yZXN0LW9hdXRoMi1qd3QifQ.ExobK5qYHzSxVpoPUvT8uQwBfZwsefYWsEjsxJopni0",
  "token_type":"bearer",
  "refresh_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiREEyRDUzMkQxQkVqd3RyZXNvdXJjZWlkIl0sInVzZXJfbmFtZSI6ImdhYnJpZWxjemFyIiwic2NvcGUiOlsicmVhZCIsIndyaXRlIl0sImF0aSI6ImY4MTJkYzBlLWZiZmItNDQ1My04ZDI2LTY5NmM2NWQ0MzA5ZiIsImV4cCI6MTUyOTg5NjQ5MCwiYXV0aG9yaXRpZXMiOlsiUk9MRV9VU0VSIl0sImp0aSI6IjZlNWMyNDRhLTU5NDQtNDNhMy05ZjJlLTkwMWQ1ZDFkNTJjYiIsImNsaWVudF9pZCI6InNwcmluZy1yZXN0LW9hdXRoMi1qd3QifQ.E3w8BWVdtFyw6eBwBokXIXRtE3-oxdwH0JgLf-13wfo",
  "expires_in":604800,
  "scope":"read write",
  "jti":"f812dc0e-fbfb-4453-8d26-696c65d4309f"
}
  • Renovar Token:
curl [CLIENT-ID]:[CLIENT-SECRET]@localhost:8080/oauth/token -d grant_type=refresh_token -d refresh_token=[REFRESH_TOKEN] 
  • Acessar recurso:
curl http://localhost:8080/api/users -H "Authorization: Bearer [ACCESS_TOKEN]"
[
  {
    "id":1,
    "username":"gabrielczar.adm",
    "firstName":"Gabriel",
    "lastName":"Czar",
    "authorities":[
      {
        "id":1,
        "name":"ROLE_ADMIN",
        "description":null,
        "authority":"ROLE_ADMIN"
      }
     ]
  },
  {
    "id":2,
    "username":"gabrielczar",
    "firstName":"Gabriel",
    "lastName":"Czar",
    "authorities":[
      {
        "id":2,
        "name":"ROLE_USER",
        "description":null,
        "authority":"ROLE_USER"
      }
    ]
  }
]

spring-rest-api-with-oauth2-and-jwt's People

Contributors

gabrielczar avatar

Watchers

 avatar  avatar

Forkers

tricksil qy8502

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.