Unverified Commit d98fd039 authored by Rafa Hernandez's avatar Rafa Hernandez
Browse files

feat(initsession): add synchronous init session by credentials method

parent 1313763b
package org.flyve.glpi;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("org.flyve.glpi.test", appContext.getPackageName());
}
}
......@@ -27,8 +27,10 @@ package org.flyve.glpi;
import android.content.Context;
import android.util.Log;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import org.flyve.glpi.query.GetAllItemQuery;
import org.flyve.glpi.query.GetAnItemQuery;
import org.flyve.glpi.query.GetSubItemQuery;
......@@ -38,8 +40,10 @@ import org.flyve.glpi.request.LostPasswordRequest;
import org.flyve.glpi.request.RecoveryPasswordRequest;
import org.flyve.glpi.response.InitSession;
import org.flyve.glpi.utils.Helpers;
import java.util.HashMap;
import java.util.Map;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
......@@ -113,6 +117,24 @@ public class GLPI extends ServiceGenerator {
});
}
/**
* Synchronous Request a session token to uses other api endpoints. with a couple login & password: 2 parameters to login with user authentication
* @param user valid user on GLPI
* @param password valid password on GLPI
* @return SessionToken
*/
public String initSessionByCredentialsSync(String user, String password) {
String authorization = Helpers.base64encode( user + ":" + password );
Call<InitSession> responseCall = interfaces.initSessionByCredentials("Basic " + authorization.trim());
try {
return responseCall.execute().body().getSessionToken();
} catch (Exception ex) {
return "";
}
}
/**
* Request a session token to uses other api endpoints. with a couple login & password: 2 parameters to login with user authentication
* @param user valid user on GLPI
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment