1 /* 2 * Make.org Core API 3 * Copyright (C) 2018 Make.org 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU Affero General Public License as 7 * published by the Free Software Foundation, either version 3 of the 8 * License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Affero General Public License for more details. 14 * 15 * You should have received a copy of the GNU Affero General Public License 16 * along with this program. If not, see <https://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package org.make.api.technical.auth 21 22 import scalaoauth2.provider.{ 23 AuthInfo, 24 AuthorizationHandler, 25 AuthorizationRequest, 26 ClientCredential, 27 GrantHandler, 28 GrantHandlerResult, 29 InvalidGrant 30 } 31 32 import scala.concurrent.{ExecutionContext, Future} 33 34 class Reconnect extends GrantHandler { 35 36 override def handleRequest[U]( 37 maybeValidatedClientCred: Option[ClientCredential], 38 request: AuthorizationRequest, 39 handler: AuthorizationHandler[U] 40 )(implicit ctx: ExecutionContext): Future[GrantHandlerResult[U]] = { 41 42 val reconnectRequest = ReconnectRequest(request) 43 handler 44 .findUser(maybeValidatedClientCred, reconnectRequest) 45 .flatMap { 46 case Some(user) => Future.successful(user) 47 case _ => Future.failed(new InvalidGrant("reconnect token or password is incorrect")) 48 } 49 .flatMap { user => 50 val scope = reconnectRequest.scope 51 val authInfo = AuthInfo(user, maybeValidatedClientCred.map(_.clientId), scope, None) 52 53 issueAccessToken(handler, authInfo) 54 } 55 } 56 } 57 58 object Reconnect { 59 val RECONNECT_TOKEN: String = "reconnect_token" 60 } 61 62 final case class ReconnectRequest(request: AuthorizationRequest) 63 extends AuthorizationRequest(request.headers, request.params) { 64 65 def reconnectToken: String = requireParam("reconnect_token") 66 67 def password: String = requireParam("password") 68 }
| Line | Stmt Id | Pos | Tree | Symbol | Tests | Code |
|---|---|---|---|---|---|---|
| 42 | 30 | 1300 - 1325 | Apply | org.make.api.technical.auth.ReconnectRequest.apply | ReconnectRequest.apply(request) | |
| 49 | 238 | 1330 - 1790 | ApplyToImplicitArgs | scala.concurrent.Future.flatMap | handler.findUser(maybeValidatedClientCred, reconnectRequest).flatMap[U](((x0$1: Option[U]) => x0$1 match { case (value: U): Some[U]((user @ _)) => scala.concurrent.Future.successful[U](user) case _ => scala.concurrent.Future.failed[Nothing](new scalaoauth2.provider.InvalidGrant("reconnect token or password is incorrect")) }))(ctx).flatMap[scalaoauth2.provider.GrantHandlerResult[U]](((user: U) => { val scope: Option[String] = reconnectRequest.scope; val authInfo: scalaoauth2.provider.AuthInfo[U] = scalaoauth2.provider.AuthInfo.apply[U](user, maybeValidatedClientCred.map[String](((x$1: scalaoauth2.provider.ClientCredential) => x$1.clientId)), scope, scala.None, scalaoauth2.provider.AuthInfo.apply$default$5[Nothing], scalaoauth2.provider.AuthInfo.apply$default$6[Nothing]); Reconnect.this.issueAccessToken[U](handler, authInfo)(ctx) }))(ctx) | |
| 59 | 115 | 1849 - 1866 | Literal | <nosymbol> | "reconnect_token" | |
| 65 | 319 | 2035 - 2066 | Apply | scalaoauth2.provider.RequestBase.requireParam | ReconnectRequest.this.requireParam("reconnect_token") | |
| 67 | 259 | 2093 - 2117 | Apply | scalaoauth2.provider.RequestBase.requireParam | ReconnectRequest.this.requireParam("password") |