GithubHelp home page GithubHelp logo

cwp0 / casdoor-java-sdk Goto Github PK

View Code? Open in Web Editor NEW

This project forked from casdoor/casdoor-java-sdk

0.0 0.0 1.0 89 KB

Java client SDK for Casdoor

Home Page: https://github.com/casdoor/casdoor

License: Apache License 2.0

Java 100.00%

casdoor-java-sdk's Introduction

casdoor-java-sdk

GitHub Actions codebeat badge codecov Javadocs Maven Central Release Gitter

This is Casdoor's SDK for java, which will allow you to easily connect your application to the Casdoor authentication system without having to implement it from scratch.

Casdoor SDK is very simple to use. We will show you the steps below.

Step1. Init Config

Initialization requires 5 parameters, which are all string type:

Name (in order) Must Description
endpoint Yes Casdoor Server Url, such as http://localhost:8000
clientId Yes Client ID for the Casdoor application
clientSecret Yes Client secret for the Casdoor application
certificate Yes The public key for the Casdoor application's cert
organizationName Yes The name for the Casdoor organization
applicationName No The name for the Casdoor application
CasdoorConfig casdoorConfig = new CasdoorConfig(endpoint, clientId, clientSecret, certificate, organizationName, applicationName);

Step2. Get Service and use

Now provide two services: CasdoorUserService, CasdoorAuthService

You can create them like

CasdoorUserService casdoorUserService = new CasdoorUserService(casdoorConfig);

UserService

CasdoorUserService support basic user operations, like:

  • GetUser(name string), get one user by user name.
  • GetUsers(), get all users.
  • UpdateUser(auth.User)/AddUser(auth.User)/DeleteUser(auth.User), write user to database.

AuthService

  1. Get token and parse

After casdoor verification passed, it will be redirected to your application with code and state, like http://forum.casbin.org?code=xxx&state=yyyy.

Your web application can get the code,state and call GetOAuthToken(code, state), then parse out jwt token.

The general process is as follows:

String token = casdoorAuthService.getOAuthToken(code, state);

CasdoorUser casdoorUser = casdoorAuthService.parseJwtToken(token);
  1. Set Session in your app

casdoorUser contains the basic information about the user provided by casdoor, you can use it as a keyword to set the session in your application, like this:

HttpSession session = request.getSession();
session.setAttribute("user", user);

SpringBoot Support

If you use SpingBoot for your application, you can use casdoor-spring-boot-starter

casdoor-java-sdk's People

Contributors

abingcbc avatar caoshengdong avatar conghuhu avatar cwp0 avatar ebreak avatar gtn1024 avatar hsluoyz avatar jakiuncle avatar resulte avatar seriouszyx avatar tangyang9464 avatar zerek-cheng avatar

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.