@@ -19,7 +19,7 @@ package securesocial.controllers
19
19
import org .joda .time .DateTime
20
20
import securesocial .core ._
21
21
import play .api .mvc .Action
22
- import scala .concurrent .{ExecutionContext , Future }
22
+ import scala .concurrent .{ ExecutionContext , Future }
23
23
import securesocial .core .SignUpEvent
24
24
import securesocial .core .AuthenticationResult .Authenticated
25
25
import securesocial .core .LoginEvent
@@ -50,44 +50,44 @@ trait BaseLoginApi[U] extends SecureSocial[U] {
50
50
51
51
def authenticate (providerId : String , builderId : String ) = Action .async { implicit request =>
52
52
import ExecutionContext .Implicits .global
53
- val result = for (
54
- builder <- env.authenticatorService.find(builderId) ;
55
- provider <- env.providers.get(providerId) if provider.isInstanceOf [ApiSupport ]
56
- ) yield {
57
- provider.asInstanceOf [ApiSupport ].authenticateForApi.flatMap {
58
- case authenticated : Authenticated =>
59
- val profile = authenticated.profile
60
- env.userService.find(profile.providerId, profile.userId).flatMap {
61
- maybeExisting =>
62
- val mode = if (maybeExisting.isDefined) SaveMode .LoggedIn else SaveMode .SignUp
63
- env.userService.save(authenticated.profile, mode).flatMap {
64
- userForAction =>
65
- logger.debug(s " [securesocial] user completed authentication: provider = ${profile.providerId}, userId: ${profile.userId}, mode = $mode" )
66
- val evt = if (mode == SaveMode .LoggedIn ) new LoginEvent (userForAction) else new SignUpEvent (userForAction)
67
- // we're not using a session here .... review this.
68
- Events .fire(evt)
69
- builder.fromUser(userForAction).map { authenticator =>
70
- val token = TokenResponse (authenticator.id, authenticator.expirationDate)
71
- Ok (Json .toJson(token))
72
- }
73
- }
74
- }
75
- case failed : AuthenticationResult .Failed =>
76
- Future .successful(BadRequest (Json .toJson(Map (" error" -> failed.error))).as(" application/json" ))
77
- case other =>
78
- // todo: review this status
79
- logger.error(s " [securesocial] unexpected result from authenticateForApi: $other" )
80
- Future .successful(InternalServerError (Json .toJson(Map (" error" -> " unexpected internal error" ))).as(" application/json" ))
81
- }
53
+ val result = for (
54
+ builder <- env.authenticatorService.find(builderId);
55
+ provider <- env.providers.get(providerId) if provider.isInstanceOf [ApiSupport ]
56
+ ) yield {
57
+ provider.asInstanceOf [ApiSupport ].authenticateForApi.flatMap {
58
+ case authenticated : Authenticated =>
59
+ val profile = authenticated.profile
60
+ env.userService.find(profile.providerId, profile.userId).flatMap {
61
+ maybeExisting =>
62
+ val mode = if (maybeExisting.isDefined) SaveMode .LoggedIn else SaveMode .SignUp
63
+ env.userService.save(authenticated.profile, mode).flatMap {
64
+ userForAction =>
65
+ logger.debug(s " [securesocial] user completed authentication: provider = ${profile.providerId}, userId: ${profile.userId}, mode = $mode" )
66
+ val evt = if (mode == SaveMode .LoggedIn ) new LoginEvent (userForAction) else new SignUpEvent (userForAction)
67
+ // we're not using a session here .... review this.
68
+ Events .fire(evt)
69
+ builder.fromUser(userForAction).map { authenticator =>
70
+ val token = TokenResponse (authenticator.id, authenticator.expirationDate)
71
+ Ok (Json .toJson(token))
72
+ }
73
+ }
74
+ }
75
+ case failed : AuthenticationResult .Failed =>
76
+ Future .successful(BadRequest (Json .toJson(Map (" error" -> failed.error))).as(" application/json" ))
77
+ case other =>
78
+ // todo: review this status
79
+ logger.error(s " [securesocial] unexpected result from authenticateForApi: $other" )
80
+ Future .successful(InternalServerError (Json .toJson(Map (" error" -> " unexpected internal error" ))).as(" application/json" ))
82
81
}
83
- result.getOrElse(Future .successful(NotFound .as(" application/json" )))
82
+ }
83
+ result.getOrElse(Future .successful(NotFound .as(" application/json" )))
84
84
}
85
85
86
86
def logout = Action .async { implicit request =>
87
87
import securesocial .core .utils ._
88
88
import ExecutionContext .Implicits .global
89
89
env.authenticatorService.fromRequest(request).flatMap {
90
- case Some (authenticator) => Ok (" " ).discardingAuthenticator(authenticator)
90
+ case Some (authenticator) => Ok (" " ).discardingAuthenticator(authenticator)
91
91
case None => Future .successful(Ok (" " ))
92
92
}
93
93
}
0 commit comments