Search in sources :

Example 1 with SessionPhoneTokenRequestJson

use of io.kamax.mxisd.controller.identity.v1.io.SessionPhoneTokenRequestJson in project mxisd by kamax-io.

the class SessionRestController method init.

@RequestMapping(value = "/validate/{medium}/requestToken")
String init(HttpServletRequest request, HttpServletResponse response, @PathVariable String medium) throws IOException {
    log.info("Request {}: {}", request.getMethod(), request.getRequestURL(), request.getQueryString());
    if (ThreePidMedium.Email.is(medium)) {
        SessionEmailTokenRequestJson req = parser.parse(request, SessionEmailTokenRequestJson.class);
        return gson.toJson(new Sid(mgr.create(request.getRemoteHost(), new ThreePid(req.getMedium(), req.getValue()), req.getSecret(), req.getAttempt(), req.getNextLink())));
    }
    if (ThreePidMedium.PhoneNumber.is(medium)) {
        SessionPhoneTokenRequestJson req = parser.parse(request, SessionPhoneTokenRequestJson.class);
        ThreePid threepid = new ThreePid(req.getMedium(), req.getValue());
        String sessionId = mgr.create(request.getRemoteHost(), threepid, req.getSecret(), req.getAttempt(), req.getNextLink());
        JsonObject res = new JsonObject();
        res.addProperty("sid", sessionId);
        res.addProperty(threepid.getMedium(), threepid.getAddress());
        return gson.toJson(res);
    }
    JsonObject obj = new JsonObject();
    obj.addProperty("errcode", "M_INVALID_3PID_TYPE");
    obj.addProperty("error", medium + " is not supported as a 3PID type");
    response.setStatus(HttpStatus.SC_BAD_REQUEST);
    return gson.toJson(obj);
}
Also used : JsonObject(com.google.gson.JsonObject) ThreePid(io.kamax.matrix.ThreePid) SessionPhoneTokenRequestJson(io.kamax.mxisd.controller.identity.v1.io.SessionPhoneTokenRequestJson) SessionEmailTokenRequestJson(io.kamax.mxisd.controller.identity.v1.io.SessionEmailTokenRequestJson)

Aggregations

JsonObject (com.google.gson.JsonObject)1 ThreePid (io.kamax.matrix.ThreePid)1 SessionEmailTokenRequestJson (io.kamax.mxisd.controller.identity.v1.io.SessionEmailTokenRequestJson)1 SessionPhoneTokenRequestJson (io.kamax.mxisd.controller.identity.v1.io.SessionPhoneTokenRequestJson)1