Search in sources :

Example 1 with SessionPhoneTokenRequestJson

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

the class SessionStartHandler method handleRequest.

@Override
public void handleRequest(HttpServerExchange exchange) {
    String medium = getPathVariable(exchange, "medium");
    if (ThreePidMedium.Email.is(medium)) {
        SessionEmailTokenRequestJson req = parseJsonTo(exchange, SessionEmailTokenRequestJson.class);
        ThreePid threepid = new ThreePid(req.getMedium(), req.getValue());
        respondJson(exchange, new RequestTokenResponse(mgr.create(getRemoteHostAddress(exchange), threepid, req.getSecret(), req.getAttempt(), req.getNextLink())));
    } else if (ThreePidMedium.PhoneNumber.is(medium)) {
        SessionPhoneTokenRequestJson req = parseJsonTo(exchange, SessionPhoneTokenRequestJson.class);
        ThreePid threepid = new ThreePid(req.getMedium(), req.getValue());
        String sessionId = mgr.create(getRemoteHostAddress(exchange), threepid, req.getSecret(), req.getAttempt(), req.getNextLink());
        JsonObject res = new JsonObject();
        res.addProperty("sid", sessionId);
        res.addProperty(threepid.getMedium(), threepid.getAddress());
        respond(exchange, res);
    } else {
        JsonObject obj = new JsonObject();
        obj.addProperty("errcode", "M_INVALID_3PID_TYPE");
        obj.addProperty("error", medium + " is not supported as a 3PID type");
        respond(exchange, HttpStatus.SC_BAD_REQUEST, obj);
    }
}
Also used : JsonObject(com.google.gson.JsonObject) RequestTokenResponse(io.kamax.mxisd.http.io.identity.RequestTokenResponse) ThreePid(io.kamax.matrix.ThreePid) SessionPhoneTokenRequestJson(io.kamax.mxisd.http.io.identity.SessionPhoneTokenRequestJson) SessionEmailTokenRequestJson(io.kamax.mxisd.http.io.identity.SessionEmailTokenRequestJson)

Aggregations

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