【问题标题】:bad credential error in spring-boot applicationspring-boot 应用程序中的错误凭据错误
【发布时间】:2018-02-07 18:04:06
【问题描述】:

我正在开发一个使用 Oauth2 并连接 SqlServer 的 spring-boot 应用程序。因此,当我点击如下所示的访问令牌 URL 时:

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

我得到的回应是:

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

所以我觉得这是因为@Table 注释和hibernate 的命名约定错误。我/我正在使用spring 1.5.9 and hibernate 5.0.12

我的 Account.java 文件是:

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;
}
}

数据库包含名称为UserInfo的表。

【问题讨论】:

  • 您可以在这里发布您的控制器和服务吗?

标签: sql-server spring hibernate spring-boot naming-conventions


【解决方案1】:

来自 OAuth2 doc(https://www.rfc-editor.org/rfc/rfc6749),错误对应:

invalid_grant 提供的授权授权(例如,授权 代码、资源所有者凭据)或刷新令牌是 无效、过期、撤销、不匹配重定向 授权请求中使用的 URI,或者被发给 另一个客户。

因此,请确保您输入了正确的赠款。如果是这样,请将@table 名称更改为“UserInfo”而不是“userinfo”。希望有帮助。 请查看此表命名策略:https://docs.jboss.org/hibernate/orm/3.5/api/org/hibernate/cfg/ImprovedNamingStrategy.html

【讨论】:

  • 以前它只是“UserInfo”,之后它会在我的数据库中自动生成一个名为“user_info”的表,其中包含以下列:名称、密码和 ID
  • 然后要么制作“@Table name”=“user_info”,要么去掉“@Table name”注解,并确保命名策略是ImprovedNamingStrategy。
  • 那也没用。我无法更改表的名称,因此仅尝试更改属性文件和代码,以便它正确映射数据库表。你知道其他解决方案吗?
  • 您是否也将“@Table name”更改为“UserInfo”?
  • 不,它没有用。它给出以下响应:{ "error": "invalid_grant", "error_description": "Bad credentials" }
猜你喜欢
  • 2014-12-25
  • 2017-05-10
  • 2018-07-16
  • 1970-01-01
  • 2019-12-08
  • 2020-09-12
  • 2018-08-30
  • 1970-01-01
相关资源
最近更新 更多