Spring security OAuth2 authentication and form login in one app

后端 未结 1 1141
旧时难觅i
旧时难觅i 2021-02-09 22:06

Is it possible to combine authoryzation and authentication by login basic and by oauth2 in one application?

My project is based on jhipster project with simple spring se

1条回答
  •  一向
    一向 (楼主)
    2021-02-09 22:21

    The apps git urls: https://github.com/rynkowsw/oauth2 it is oauth2 app https://github.com/rynkowsw/web-and-oauth2-security this is web and oauth2 security app

    This app are adapted from jhipster.github.io

    to run app you need have postgres db in localhost, like in db resource file:

        driver-class-name: org.postgresql.ds.PGSimpleDataSource
        url: jdbc:postgresql://localhost:5432/gymapp
        name: gymapp
        serverName: localhost:5432
        username: postgres
        password: jaja
    

    To test app the fastest way is:

     http://localhost:8080/oauth/token
     headers:  Authorization: Basic amhpcHN0ZXJhcHA6bXlTZWNyZXRPQXV0aFNlY3JldA==
    

    this string after basic is combination default jhispter oauth secret and clientid base64 encrypt result

    then

      http://localhost:8080/api/account
      headers:  Authorization: bearer [token from response in first request]
    

    For this same db, result for oauth are: for oauth2 app

    {
     login: "user"
     password: null
     firstName: "User"
     lastName: "User"
     email: "user@localhost"
     activated: true
     langKey: "en"
     authorities: [1]
     0:  "ROLE_USER"
     -
    }
    

    for web + oauth2 security:

     {
      login: "anonymousUser"
      password: null
      firstName: "Anonymous"
      lastName: "User"
      email: "anonymous@localhost"
      activated: true
      langKey: "en"
      authorities: [0]
      }
    

    0 讨论(0)
提交回复
热议问题