public KnetikApiResponse CustomLogin( string serviceEndpoint, string usernameOrEmail, string password, bool isEmail, Action<KnetikApiResponse> cb = null ) { JSONObject json = new JSONObject (JSONObject.Type.OBJECT); if (isEmail) { json.AddField("email", usernameOrEmail); } else { json.AddField("username", usernameOrEmail); } json.AddField("password", password); json.AddField ("serial", KnetikApiUtil.getDeviceSerial()); json.AddField ("mac_address", KnetikApiUtil.getMacAddress ()); // Device Type is currently limited to 3 characters in the DB json.AddField ("device_type", KnetikApiUtil.getDeviceType()); json.AddField ("signature", KnetikApiUtil.getDeviceSignature()); string body = json.Print (); KnetikRequest req = CreateRequest(serviceEndpoint, body, "POST", -1, ""); KnetikApiResponse res = new KnetikLoginResponse(this, req, cb); return res; }
public KnetikApiResponse Login( string username, string password, Action<KnetikApiResponse> cb = null ) { int timestamp = GetTimestamp (); string endpoint; string body; string serviceBundle = null; JSONObject json = new JSONObject (JSONObject.Type.OBJECT); json.AddField ("serial", KnetikApiUtil.getDeviceSerial()); json.AddField ("mac_address", KnetikApiUtil.getMacAddress ()); // Device Type is currently limited to 3 characters in the DB json.AddField ("device_type", KnetikApiUtil.getDeviceType()); json.AddField ("signature", KnetikApiUtil.getDeviceSignature()); if (Authentication == null || Authentication == "" || Authentication == "default") { endpoint = SessionEndpoint; Username = username; Password = EncodePassword(password, timestamp); } else { // use SSO serviceBundle = Authentication; endpoint = "login"; json.AddField("username", username); json.AddField("email", username); json.AddField("password", password); } body = json.Print (); KnetikRequest req = CreateRequest(endpoint, body, "post", timestamp, serviceBundle); KnetikApiResponse res = new KnetikLoginResponse(this, req, cb); return res; }
public KnetikApiResponse GuestLogin( Action<KnetikApiResponse> cb = null ) { Username = ""; Password = ""; Session = ""; JSONObject json = new JSONObject (JSONObject.Type.OBJECT); json.AddField ("serial", KnetikApiUtil.getDeviceSerial()); json.AddField ("mac_address", KnetikApiUtil.getMacAddress ()); // Device Type is currently limited to 3 characters in the DB json.AddField ("device_type", KnetikApiUtil.getDeviceType()); json.AddField ("signature", KnetikApiUtil.getDeviceSignature()); String body = json.Print(); KnetikRequest req = CreateRequest(SessionEndpoint, body); KnetikApiResponse res = new KnetikLoginResponse(this, req, cb); return res; }
public KnetikApiResponse Login( string username, string password, Action<KnetikApiResponse> cb = null ) { int timestamp = GetTimestamp (); string body; string serviceBundle = null; StringBuilder bodyBuilder = new StringBuilder(); bodyBuilder.AppendFormat( "grant_type=password&username={0}&password={1}&client_id={2}&client_secret={3}", System.Uri.EscapeDataString(username), System.Uri.EscapeDataString(password), System.Uri.EscapeDataString(ClientID), System.Uri.EscapeDataString(ClientSecret) ); body = bodyBuilder.ToString(); KnetikRequest req = CreateRequest(SessionEndpoint, body, "post", timestamp, serviceBundle, true); KnetikApiResponse res; if(cb != null) { res = new KnetikLoginResponse(this, req, (resp) => { if(resp.Status == KnetikApiResponse.StatusType.Success) { PlayerPrefs.SetString(UsernameKey, username); PlayerPrefs.SetString(PasswordKey, password); LoadUserProfile(); } else { if(OnLoginFailed != null) { if (resp.Request.response != null && !string.IsNullOrEmpty(resp.Request.response.Text)) { JSONObject j = new JSONObject(resp.Request.response.Text); string error = j["error_description"].str; OnLoginFailed(error); } else { OnLoginFailed(resp.ErrorMessage); } } } cb(resp); }); } else { res = new KnetikLoginResponse(this, req, null); if(res.Status == KnetikApiResponse.StatusType.Success) { PlayerPrefs.SetString(UsernameKey, username); PlayerPrefs.SetString(PasswordKey, password); LoadUserProfile(); } else { if (OnLoginFailed != null) { if (res.Body != null && !string.IsNullOrEmpty(res.Body["error"]["message"])) { OnLoginFailed(res.Body["error"]["message"]); } else { OnLoginFailed(res.ErrorMessage); } } } } return res; }
public KnetikApiResponse refreshSession( Action<KnetikApiResponse> cb = null ) { int timestamp = GetTimestamp (); string body; string serviceBundle = null; StringBuilder bodyBuilder = new StringBuilder(); bodyBuilder.AppendFormat( "grant_type=refresh_token&refresh_token={0}&client_id={1}&client_secret={2}", System.Uri.EscapeDataString(KnetikClient.Instance.RefreshToken), System.Uri.EscapeDataString(ClientID), System.Uri.EscapeDataString(ClientSecret) ); body = bodyBuilder.ToString(); KnetikRequest req = CreateRequest(SessionEndpoint, body, "post", timestamp, serviceBundle, true); KnetikApiResponse res = new KnetikLoginResponse(this, req, cb); return res; }
/* Login With custome Grant Type @param Dictionary<string,string> */ public KnetikApiResponse Login(Dictionary<string,string> parameters, Action<KnetikApiResponse> cb = null ) { int timestamp = GetTimestamp (); string body; string serviceBundle = null; body = KnetikApiUtil.buildStringRequestFromDictionary (parameters); KnetikRequest req = CreateRequest(SessionEndpoint, body, "post", timestamp, serviceBundle, true); KnetikApiResponse res = new KnetikLoginResponse(this, req, cb); return res; }