mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 16:56:56 +00:00
Endpoint /banks/BANK_ID/my/consent-requests/SCA_METHOD - Added email sending
This commit is contained in:
parent
85f1b1ff32
commit
01fdd30bca
@ -103,7 +103,7 @@ object Consent {
|
||||
}
|
||||
|
||||
private def checkConsent(consent: ConsentJWT, consentIdAsJwt: String): Box[Boolean] = {
|
||||
Consents.ConsentProvider.vend.getConsentByConsentId(consent.jti) match {
|
||||
Consents.consentProvider.vend.getConsentByConsentId(consent.jti) match {
|
||||
case Full(c) if c.mStatus == ConsentStatus.ACCEPTED.toString =>
|
||||
verifyHmacSignedJwt(consentIdAsJwt, c) match {
|
||||
case true =>
|
||||
|
||||
@ -37,8 +37,9 @@ import net.liftweb.common.{Empty, Full}
|
||||
import net.liftweb.http.provider.HTTPParam
|
||||
import net.liftweb.http.rest.RestHelper
|
||||
import net.liftweb.json.parse
|
||||
import net.liftweb.util.Helpers
|
||||
import net.liftweb.util.{Helpers, Mailer}
|
||||
import net.liftweb.util.Helpers.tryo
|
||||
import net.liftweb.util.Mailer.{From, PlainMailBodyType, Subject, To}
|
||||
import org.apache.commons.lang3.Validate
|
||||
|
||||
import scala.collection.immutable.{List, Nil}
|
||||
@ -3138,13 +3139,13 @@ trait APIMethods310 {
|
||||
implementedInApiVersion,
|
||||
nameOf(createConsent),
|
||||
"POST",
|
||||
"/banks/BANK_ID/my/consent-requests/SCA_METHOD",
|
||||
"Create Consent Request",
|
||||
"/banks/BANK_ID/my/consent/SCA_METHOD",
|
||||
"Create Consent",
|
||||
s"""
|
||||
|Create consent request
|
||||
|Create consent
|
||||
|""",
|
||||
PostConsentRequestJsonV310(phone_number = "0049182234430", `for`="ALL_MY_ACCOUNTS", view="owner"),
|
||||
emptyObjectJson,
|
||||
PostConsentRequestJsonV310(email = "marko@tesobe.com", `for`="ALL_MY_ACCOUNTS", view="owner"),
|
||||
ConsentRequestJsonV310(consent_id = "eyJhbGciOiJIUzI1NiJ9.eyJlbnRpdGxlbWVudHMiOltdLCJjcmVhdGVkQnlVc2VySWQiOiJhYjY1MzlhOS1iMTA1LTQ0ODktYTg4My0wYWQ4ZDZjNjE2NTciLCJzdWIiOiIyMWUxYzhjYy1mOTE4LTRlYWMtYjhlMy01ZTVlZWM2YjNiNGIiLCJhdWQiOiJlanpuazUwNWQxMzJyeW9tbmhieDFxbXRvaHVyYnNiYjBraWphanNrIiwibmJmIjoxNTUzNTU0ODk5LCJpc3MiOiJodHRwczpcL1wvd3d3Lm9wZW5iYW5rcHJvamVjdC5jb20iLCJleHAiOjE1NTM1NTg0OTksImlhdCI6MTU1MzU1NDg5OSwianRpIjoiMDlmODhkNWYtZWNlNi00Mzk4LThlOTktNjYxMWZhMWNkYmQ1Iiwidmlld3MiOlt7ImFjY291bnRfaWQiOiJtYXJrb19wcml2aXRlXzAxIiwiYmFua19pZCI6ImdoLjI5LnVrLngiLCJ2aWV3X2lkIjoib3duZXIifSx7ImFjY291bnRfaWQiOiJtYXJrb19wcml2aXRlXzAyIiwiYmFua19pZCI6ImdoLjI5LnVrLngiLCJ2aWV3X2lkIjoib3duZXIifV19.8cc7cBEf2NyQvJoukBCmDLT7LXYcuzTcSYLqSpbxLp4"),
|
||||
List(UnknownError),
|
||||
Catalogs(Core, notPSD2, OBWG),
|
||||
apiTagCustomer :: apiTagNewStyle :: Nil)
|
||||
@ -3162,14 +3163,25 @@ trait APIMethods310 {
|
||||
consentJson <- NewStyle.function.tryons(failMsg, 400, callContext) {
|
||||
json.extract[PostConsentRequestJsonV310]
|
||||
}
|
||||
consent <- Future(Consents.ConsentProvider.vend.createConsent()) map {
|
||||
consent <- Future(Consents.consentProvider.vend.createConsent()) map {
|
||||
i => connectorEmptyResponse(i, callContext)
|
||||
}
|
||||
consentJWT = Consent.createConsentJWT(user, consentJson.view, consent.secret, consent.consentId)
|
||||
_ <- Future(Consents.ConsentProvider.vend.updateConsent(consent.consentId, consentJWT)) map {
|
||||
_ <- Future(Consents.consentProvider.vend.updateConsent(consent.consentId, consentJWT)) map {
|
||||
i => connectorEmptyResponse(i, callContext)
|
||||
}
|
||||
} yield {
|
||||
sca_method match {
|
||||
case "email" => // Send the email
|
||||
val params = PlainMailBodyType(consent.challenge) :: List(To(consentJson.email))
|
||||
Mailer.sendMail(
|
||||
From("challenge@tesobe.com"),
|
||||
Subject("Challenge request"),
|
||||
params :_*
|
||||
)
|
||||
case "sms" =>
|
||||
case _ =>
|
||||
}
|
||||
(ConsentRequestJsonV310(consentJWT), HttpCode.`201`(callContext))
|
||||
}
|
||||
}
|
||||
|
||||
@ -471,7 +471,7 @@ case class MeetingsJsonV310(
|
||||
meetings: List[MeetingJsonV310]
|
||||
)
|
||||
|
||||
case class PostConsentRequestJsonV310(phone_number: String, `for`: String, view: String)
|
||||
case class PostConsentRequestJsonV310(email: String, `for`: String, view: String)
|
||||
case class ConsentRequestJsonV310(consent_id: String)
|
||||
|
||||
object JSONFactory310{
|
||||
|
||||
@ -4,7 +4,7 @@ import net.liftweb.common.Box
|
||||
import net.liftweb.util.SimpleInjector
|
||||
|
||||
object Consents extends SimpleInjector {
|
||||
val ConsentProvider = new Inject(buildOne _) {}
|
||||
val consentProvider = new Inject(buildOne _) {}
|
||||
def buildOne: ConsentProvider = MappedConsentProvider
|
||||
}
|
||||
|
||||
@ -18,6 +18,7 @@ trait Consent {
|
||||
def consentId: String
|
||||
def secret: String
|
||||
def status: String
|
||||
def challenge: String
|
||||
def jsonWebToken: String
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package code.consent
|
||||
|
||||
import scala.util.Random
|
||||
|
||||
import code.api.util.ErrorMessages
|
||||
import code.util.MappedUUID
|
||||
import net.liftweb.common.{Box, Empty, Failure, Full}
|
||||
@ -45,11 +47,15 @@ class MappedConsent extends Consent with LongKeyedMapper[MappedConsent] with IdP
|
||||
object mConsentId extends MappedUUID(this)
|
||||
object mSecret extends MappedUUID(this)
|
||||
object mStatus extends MappedString(this, 20)
|
||||
object mChallenge extends MappedString(this, 10) {
|
||||
override def defaultValue = Random.nextInt(99999999).toString()
|
||||
}
|
||||
object mJsonWebToken extends MappedString(this, 1024)
|
||||
|
||||
override def consentId: String = mConsentId.get
|
||||
override def secret: String = mSecret.get
|
||||
override def status: String = mStatus.get
|
||||
override def challenge: String = mChallenge.get
|
||||
override def jsonWebToken: String = mJsonWebToken.get
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user