GithubHelp home page GithubHelp logo

lex4hex / secured-shop Goto Github PK

View Code? Open in Web Editor NEW
4.0 3.0 1.0 17.82 MB

Simple Java Spring REST API to test OAuth2

License: MIT License

Java 72.32% TSQL 27.68%
oauth postgres spring-boot spring-security-oauth2 spring-security

secured-shop's Introduction

Simple Spring API to experiment with OAuth2.

Warning! Contains some really bad code practices, used in educational purposes only :)

Technological stack

  • Java 8
  • Postgres 9.6
  • Hibernate 5.2
  • Spring MVC, Boot, Security 4.3
  • Spring OAuth 2
  • Maven 3

Deploy and configuration

  • Create database in Postgres and restore from dump shopDump.sql
  • Edit application.properties in resources accordingly to your database settings
  • Run application as Spring Boot app in IDE
  • Alternatively you can build a jar using mvn clean install spring-boot:repackage and run it by java -jar shopAPI.jar

Authentication, authorization and credentials

  • In database dump there is already one admin user: admin:abc123
  • For client's authorization use default HTTP authorization header Authorization: Basic dHJ1c3RlZDphYmMxMjM= or trusted:secret login/password combination
  • For simplicity OAuth default tables located in the same schema
  • You can edit access and refresh token validity in oauth_client_details table
  • To access REST API secured actions you have to provide access token in request params e.g. access_token=c15de2f5-d7ec-4948-82ac-07ba2d1fb27d But without Authorization header.

REST actions

Authentication

  • Obtain access token POST oauth/token?grant_type=password&username=admin&password=abc123 You must provide client's authorization headers
  • Refresh access token POST oauth/token?grant_type=refresh_token&refresh_token=<REFRESH_TOKEN> You must provide client's authorization headers

Cart Controller Actions

  • addProductToCart - public POST /api/shop/cart/{cartId}/add/{productId}
  • createCart - public POST /api/shop/cart/customer/{customerId}

Order Controller Actions

  • createOrder - public POST /api/shop/customer/{id}/order
  • listAllOrders - admin GET /api/shop/orders

Customer Controller Actions

  • createCustomer - admin POST /api/shop/customers/{name}

Product Controller Actions

  • listAllProducts - public GET /api/shop/products
  • getProduct - admin GET /api/shop/products/{id}
  • createProduct - admin POST /api/shop/products
  • updateProduct - admin PUT /api/shop/products/{id}
  • deleteProduct - admin DELETE /api/shop/products/{id}

secured-shop's People

Contributors

dependabot[bot] avatar lex4hex avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

gneginskiy

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.