java - 未找到请求“GET /authenticate/github? 在游戏框架 2.6 的安全社交中
问题描述
我一直在尝试在 play 2.6 中使用securesocial。我正在使用主快照。当我单击 GitHub 图标时,它会将我导航到 github.com,当我输入我的用户名和密码时,我会收到未找到操作错误http://localhost:9000/authenticate/github?error=redirect_uri_mismatch&error_description=The+redirect_uri+MUST +match+the+registered+callback+URL+for+this+application.&error_uri=https%3A%2F%2Fdeveloper.github.com%2Fapps%2Fmanaging-oauth-apps%2Ftroubleshooting-authorization-request-errors%2F%23redirect -uri-mismatch&state=9eb23bec-37b6-4930-9b76-899ff8e1fbe1。
下面是我的路线文件
GET / controllers.Application.index
GET /home @controllers.Application.goHome
GET /userAware @controllers.Application.userAware
GET /link-result @controllers.Application.linkResult
GET /current-user @controllers.Application.currentUser
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
-> /auth securesocial.Routes
应用程序.java
package controllers;
import play.mvc.*;
import com.google.inject.Inject;
import play.Logger;
import play.libs.F;
import services.MyUserService;
import securesocial.core.BasicProfile;
import securesocial.core.RuntimeEnvironment;
import securesocial.core.java.SecureSocial;
import securesocial.core.java.SecuredAction;
import securesocial.core.java.UserAwareAction;
import java.util.concurrent.CompletionStage;
import java.util.function.Function;
import views.html.*;
/**
* This controller contains an action to handle HTTP requests
* to the application's home page.
*/
public class Application extends Controller {
/**
* An action that renders an HTML page with a welcome message.
* The configuration in the <code>routes</code> file means that
* this method will be called when the application receives a
* <code>GET</code> request with a path of <code>/</code>.
*/
public static Logger.ALogger logger = Logger.of("application.controllers.Application");
private RuntimeEnvironment env;
/**
* A constructor needed to get a hold of the environment instance.
* This could be injected using a DI framework instead too.
*
* @param env
*/
@Inject()
public Application (RuntimeEnvironment env) {
this.env = env;
}
/**
* This action only gets called if the user is logged in.
*
* @return
*/
@SecuredAction
public Result index() {
if(logger.isDebugEnabled()){
logger.debug("access granted to index");
}
MyUserService user = (MyUserService) ctx().args.get(SecureSocial.USER_KEY);
return ok(index.render(user, SecureSocial.env()));
}
@UserAwareAction
public Result userAware() {
MyUserService myUser = (MyUserService) ctx().args.get(SecureSocial.USER_KEY);
String userName ;
if ( myUser != null ) {
BasicProfile user = myUser.main;
if ( user.firstName().isDefined() ) {
userName = user.firstName().get();
} else if ( user.fullName().isDefined()) {
userName = user.fullName().get();
} else {
userName = "authenticated user";
}
} else {
userName = "guest";
}
return ok("Hello " + userName + ", you are seeing a public page");
}
@SecuredAction
public Result goHome() {
if(logger.isDebugEnabled()){
logger.debug("access granted to Home");
}
MyUserService user = (MyUserService) ctx().args.get(SecureSocial.USER_KEY);
return ok(home.render());
}
@SecuredAction
public Result linkResult() {
MyUserService current = (MyUserService) ctx().args.get(SecureSocial.USER_KEY);
return ok(linkResult.render(current, current.identities));
}
/**
* Sample use of SecureSocial.currentUser. Access the /current-user to test it
*/
public CompletionStage<Result> currentUser() {
return SecureSocial.currentUser(env).thenApply( new Function<Object, Result>() {
public Result apply(Object maybeUser) {
String id;
if ( maybeUser != null ) {
MyUserService user = (MyUserService) maybeUser;
id = user.main.userId();
} else {
id = "not available. Please log in.";
}
return ok("your id is " + id);
}
});
}
}
在securesocial.conf中我添加了onLoginGoTo = /home
解决方案
看起来您需要使用/authenticate
而不是/auth
:
-> /authenticate securesocial.Routes
或者,如果您想使用 url,请将其与auth
而不是一起使用authenticate
:
http://localhost:9000/auth/github?error=redirect_uri_mismatch&error_description=The+redirect_uri+MUST+match+the+registered+callback+URL+for+this+application.&error_uri=https%3A%2F%2Fdeveloper.github.com%2Fapps%2Fmanaging-oauth-apps%2Ftroubleshooting-authorization-request-errors%2F%23redirect-uri-mismatch&state=9eb23bec-37b6-4930-9b76-899ff8e1fbe1
推荐阅读
- mysql - MySQL 中针对 CASCADE、RESTRICT、NO ACTION、SET NULL、SET DEFAULT 的删除行为在 MySQL 中的对应配置是什么
- android - 使用 ScaleType 进行毕加索变换
- r - 如何根据是否满足特定条件在数据表中绘制信息?
- reactive-programming - RxSwift 中的 PublishSubject 和 PublishRelay 有什么区别?
- store - 高分辨率图标为 128px 但提交被拒绝
- javascript - 使用 Ajax 发送数据并在控制器中接收时出错
- ruby-on-rails - 未找到动作记录。找不到 id=
- wpf - 对话框应该在按钮单击时出现在前面
- java - 雪花集成测试实施
- ios - Swift - 从文档目录中删除自定义文件夹