-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: How to bypass authentication for crawlers? #58
Comments
質問はここでもTwitterでもOKです。はい、ここだと英語にして頂けると助かります! It may be misplaced kindness... There are two approaches.
best regards, |
Thanks for the answer and the advice for the session issue.
I chose the former. Now, my code is like the following and I'm not sure what to do in authenticationFailed. I'm still not used to this module, so my understanding might be fundamentally wrong... object Auth extends Controller with LoginLogout with AuthConfigImpl {
def authenticate = Action { implicit request =>
request.session.get("user_id").map{userId =>
gotoLoginSucceeded(userId.toInt)
}.getOrElse{
BadRequest("direct access?")
}
}
}
trait AuthConfigImpl extends AuthConfig {
def authenticationFailed(request: RequestHeader): Result = {
request.headers.get("X-Requested-With") match {
case Some("XMLHttpRequest") =>
Unauthorized("Authentication failed")
case _ =>
if (!UserAgent.isCrawler(request)) {
val gu = GuestUser.create
Redirect(routes.Auth.authenticate).withSession("access_uri" -> request.uri, "user_id" -> gu.id.toString)
} else {
// This won't work since crawlers don't accept cookies.
Redirect(routes.Auth.authenticate).withSession("access_uri" -> request.uri, "user_id" -> CrawlerUser.id.toString)
}
}
}
} Thanks! |
質問ってここでいいんでしょうか&英語の方がいいですよね?
Hi,
I started using play2-auth about a week ago, and managed to get it working (more or less). Thanks for the great module!
I'm developing a web site where users can post text, like one of those online forums, and here's my scenario:
Actually, the above requirements have been fulfilled by creating a user in AuthConfigImpl.authenticationFailed.
Now, I don't want to create temporary users for crawlers, and my question is, what's the optimal way to achieve that?
Thanks!
よろしくお願いします。
The text was updated successfully, but these errors were encountered: