简体   繁体   中英

bad credential error in spring-boot application

I'm working on a spring-boot application that uses Oauth2 and connects SqlServer. So when I'm hitting the access token URL that looks like this:

localhost:8081/oauth/token?client_secret=secret&client_id=web&grant_type=password&username=XXXX&password=XXXXXXX

And the response which I'm getting is:

{ "error": "invalid_grant", "error_description": "Bad credentials" }

So I feel it is because of @Table annotation and the naming convention bug which hibernate have. I/m using spring 1.5.9 and hibernate 5.0.12 .

My Account.java file is:

package com.oauth.oserver.entities;
import javax.persistence.*;


@Entity
@Table(name = "userinfo")
public class Account {

@Id
@GeneratedValue
private Long id;
@Column(name = "name")
private String username;
@Column(name = "password")
private String password;

public Account() {
}

public Account(String username, String password) {

    this.username = username;
    this.password = password;
}

public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}

public String getUsername() {
    return username;

}

public void setUsername(String username) {
    this.username = username;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}
}

Database contains table whose name is UserInfo .

From OAuth2 doc( https://tools.ietf.org/html/rfc6749 ), the error corresponds to :

invalid_grant The provided authorization grant (eg, authorization code, resource owner credentials) or refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client.

So please make sure that you have entered the right grants. If so, change @table name to "UserInfo" instead of "userinfo". Hope that helps. And please check this out for table naming strategies : https://docs.jboss.org/hibernate/orm/3.5/api/org/hibernate/cfg/ImprovedNamingStrategy.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM