-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a693c86
commit 839d702
Showing
12 changed files
with
578 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
230 changes: 230 additions & 0 deletions
230
LoginRadius-JavaSDK/src/main/java/com/loginradius/sdk/api/cloud/SsoJwtApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,230 @@ | ||
/* | ||
* | ||
* Created by LoginRadius Development Team | ||
Copyright 2019 LoginRadius Inc. All rights reserved. | ||
*/ | ||
|
||
package com.loginradius.sdk.api.cloud; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.reflect.TypeToken; | ||
import com.loginradius.sdk.helper.JsonDeserializer; | ||
import com.loginradius.sdk.helper.LoginRadiusRequest; | ||
import com.loginradius.sdk.helper.LoginRadiusValidator; | ||
import com.loginradius.sdk.models.requestmodels.SsoAuthenticationModel; | ||
import com.loginradius.sdk.models.responsemodels.SsoJwtResponseData; | ||
import com.loginradius.sdk.util.AsyncHandler; | ||
import com.loginradius.sdk.util.ErrorResponse; | ||
import com.loginradius.sdk.util.LoginRadiusSDK; | ||
|
||
|
||
public class SsoJwtApi { | ||
private static Gson gson =new Gson(); | ||
|
||
public SsoJwtApi(){ | ||
if (!LoginRadiusSDK.validate()){ | ||
throw new LoginRadiusSDK.InitializeException(); | ||
} | ||
} | ||
|
||
|
||
|
||
// <summary> | ||
// This API is used to get the JWT token by access token. | ||
// </summary> | ||
// <param name="accessToken">Uniquely generated identifier key by LoginRadius that is activated after successful authentication.</param> | ||
// <param name="jwtAppName">Jwt App Name</param> | ||
// <returns>Response containing Definition Complete SsoJwtResponseData data</returns> | ||
|
||
public void jwtTokenByAccessToken(String accessToken, String jwtAppName,final AsyncHandler<SsoJwtResponseData> handler) { | ||
|
||
if (LoginRadiusValidator.isNullOrWhiteSpace(accessToken)) { | ||
throw new IllegalArgumentException(LoginRadiusValidator.getValidationMessage("accessToken")); | ||
} | ||
|
||
if (LoginRadiusValidator.isNullOrWhiteSpace(jwtAppName)) { | ||
throw new IllegalArgumentException(LoginRadiusValidator.getValidationMessage("jwtAppName")); | ||
} | ||
|
||
Map<String, String> queryParameters = new HashMap<String, String>(); | ||
queryParameters.put("apiKey", LoginRadiusSDK.getApiKey()); | ||
queryParameters.put("access_token", accessToken); | ||
queryParameters.put("jwtapp", jwtAppName); | ||
|
||
String resourcePath = "sso/jwt/api/token"; | ||
|
||
LoginRadiusRequest.execute("GET", resourcePath, queryParameters,null,new AsyncHandler<String>() { | ||
|
||
@Override | ||
public void onSuccess(String response) { | ||
TypeToken<SsoJwtResponseData> typeToken = new TypeToken<SsoJwtResponseData>() {}; | ||
SsoJwtResponseData successResponse = JsonDeserializer.deserializeJson(response,typeToken); | ||
handler.onSuccess(successResponse); | ||
} | ||
|
||
@Override | ||
public void onFailure(ErrorResponse errorResponse) { | ||
handler.onFailure(errorResponse); | ||
} | ||
}); | ||
} | ||
|
||
// <summary> | ||
// This API is used to get a JWT token by Email and Password. | ||
// </summary> | ||
// <param name="ssoAuthenticationModel">Model Class containing Definition of payload for SSO Jwt Cloud Api</param> | ||
// <param name="accessToken">Uniquely generated identifier key by LoginRadius that is activated after successful authentication.</param> | ||
// <param name="jwtAppName">Jwt App Name</param> | ||
// <returns>Response containing Definition Complete SsoJwtResponseData data</returns> | ||
|
||
public void jwtTokenByEmail(SsoAuthenticationModel ssoAuthenticationModel, String jwtAppName,String emailTemplate,String loginUrl, String verificationUrl,final AsyncHandler<SsoJwtResponseData> handler) { | ||
|
||
if (ssoAuthenticationModel == null) { | ||
throw new IllegalArgumentException(LoginRadiusValidator.getValidationMessage("ssoAuthenticationModel")); | ||
} | ||
if (LoginRadiusValidator.isNullOrWhiteSpace(jwtAppName)) { | ||
throw new IllegalArgumentException(LoginRadiusValidator.getValidationMessage("jwtAppName")); | ||
} | ||
|
||
Map<String, String> queryParameters = new HashMap<String, String>(); | ||
queryParameters.put("apiKey", LoginRadiusSDK.getApiKey()); | ||
queryParameters.put("jwtapp", jwtAppName); | ||
|
||
if (!LoginRadiusValidator.isNullOrWhiteSpace(emailTemplate)) { | ||
queryParameters.put("emailTemplate", emailTemplate); | ||
} | ||
|
||
if (!LoginRadiusValidator.isNullOrWhiteSpace(loginUrl)) { | ||
queryParameters.put("loginUrl", loginUrl); | ||
} | ||
|
||
if (!LoginRadiusValidator.isNullOrWhiteSpace(verificationUrl)) { | ||
queryParameters.put("verificationurl", verificationUrl); | ||
} | ||
String resourcePath = "sso/jwt/api/login"; | ||
|
||
LoginRadiusRequest.execute("POST", resourcePath, queryParameters,gson.toJson(ssoAuthenticationModel),new AsyncHandler<String>() { | ||
|
||
@Override | ||
public void onSuccess(String response) { | ||
TypeToken<SsoJwtResponseData> typeToken = new TypeToken<SsoJwtResponseData>() {}; | ||
SsoJwtResponseData successResponse = JsonDeserializer.deserializeJson(response,typeToken); | ||
handler.onSuccess(successResponse); | ||
} | ||
|
||
@Override | ||
public void onFailure(ErrorResponse errorResponse) { | ||
handler.onFailure(errorResponse); | ||
} | ||
}); | ||
} | ||
|
||
// <summary> | ||
// This API is used to get a JWT token by UserName and Password. | ||
// </summary> | ||
// <param name="ssoAuthenticationModel">Model Class containing Definition of payload for SSO Jwt Cloud Api</param> | ||
// <param name="accessToken">Uniquely generated identifier key by LoginRadius that is activated after successful authentication.</param> | ||
// <param name="jwtAppName">Jwt App Name</param> | ||
// <returns>Response containing Definition Complete SsoJwtResponseData data</returns> | ||
|
||
public void jwtTokenByUserName(SsoAuthenticationModel ssoAuthenticationModel, String jwtAppName, String emailTemplate,String loginUrl, String verificationUrl, final AsyncHandler<SsoJwtResponseData> handler) { | ||
|
||
|
||
if (ssoAuthenticationModel == null) { | ||
throw new IllegalArgumentException(LoginRadiusValidator.getValidationMessage("ssoAuthenticationModel")); | ||
} | ||
|
||
if (LoginRadiusValidator.isNullOrWhiteSpace(jwtAppName)) { | ||
throw new IllegalArgumentException(LoginRadiusValidator.getValidationMessage("jwtAppName")); | ||
} | ||
|
||
Map<String, String> queryParameters = new HashMap<String, String>(); | ||
queryParameters.put("apiKey", LoginRadiusSDK.getApiKey()); | ||
queryParameters.put("jwtapp", jwtAppName); | ||
|
||
if (!LoginRadiusValidator.isNullOrWhiteSpace(emailTemplate)) { | ||
queryParameters.put("emailTemplate", emailTemplate); | ||
} | ||
|
||
if (!LoginRadiusValidator.isNullOrWhiteSpace(loginUrl)) { | ||
queryParameters.put("loginUrl", loginUrl); | ||
} | ||
|
||
if (!LoginRadiusValidator.isNullOrWhiteSpace(verificationUrl)) { | ||
queryParameters.put("verificationurl", verificationUrl); | ||
} | ||
String resourcePath = "sso/jwt/api/login"; | ||
|
||
LoginRadiusRequest.execute("POST", resourcePath, queryParameters,gson.toJson(ssoAuthenticationModel),new AsyncHandler<String>() { | ||
|
||
@Override | ||
public void onSuccess(String response) { | ||
TypeToken<SsoJwtResponseData> typeToken = new TypeToken<SsoJwtResponseData>() {}; | ||
SsoJwtResponseData successResponse = JsonDeserializer.deserializeJson(response,typeToken); | ||
handler.onSuccess(successResponse); | ||
} | ||
|
||
@Override | ||
public void onFailure(ErrorResponse errorResponse) { | ||
handler.onFailure(errorResponse); | ||
} | ||
}); | ||
} | ||
// <summary> | ||
// This API is used to get a JWT token by Phone and Password. | ||
// </summary> | ||
// <param name="ssoAuthenticationModel">Model Class containing Definition of payload for SSO Jwt Cloud Api</param> | ||
// <param name="accessToken">Uniquely generated identifier key by LoginRadius that is activated after successful authentication.</param> | ||
// <param name="jwtAppName">Jwt App Name</param> | ||
// <returns>Response containing Definition Complete SsoJwtResponseData data</returns> | ||
|
||
public void jwtTokenByPhone(SsoAuthenticationModel ssoAuthenticationModel,String jwtAppName,String emailTemplate,String loginUrl, String verificationUrl,final AsyncHandler<SsoJwtResponseData> handler) { | ||
|
||
if (ssoAuthenticationModel == null) { | ||
throw new IllegalArgumentException(LoginRadiusValidator.getValidationMessage("ssoAuthenticationModel")); | ||
} | ||
|
||
if (LoginRadiusValidator.isNullOrWhiteSpace(jwtAppName)) { | ||
throw new IllegalArgumentException(LoginRadiusValidator.getValidationMessage("jwtAppName")); | ||
} | ||
|
||
Map<String, String> queryParameters = new HashMap<String, String>(); | ||
queryParameters.put("apiKey", LoginRadiusSDK.getApiKey()); | ||
queryParameters.put("jwtapp", jwtAppName); | ||
|
||
|
||
if (!LoginRadiusValidator.isNullOrWhiteSpace(emailTemplate)) { | ||
queryParameters.put("emailTemplate", emailTemplate); | ||
} | ||
|
||
if (!LoginRadiusValidator.isNullOrWhiteSpace(loginUrl)) { | ||
queryParameters.put("loginUrl", loginUrl); | ||
} | ||
|
||
if (!LoginRadiusValidator.isNullOrWhiteSpace(verificationUrl)) { | ||
queryParameters.put("verificationurl", verificationUrl); | ||
} | ||
|
||
String resourcePath = "sso/jwt/api/login"; | ||
|
||
LoginRadiusRequest.execute("POST", resourcePath, queryParameters,gson.toJson(ssoAuthenticationModel),new AsyncHandler<String>() { | ||
|
||
@Override | ||
public void onSuccess(String response) { | ||
TypeToken<SsoJwtResponseData> typeToken = new TypeToken<SsoJwtResponseData>() {}; | ||
SsoJwtResponseData successResponse = JsonDeserializer.deserializeJson(response,typeToken); | ||
handler.onSuccess(successResponse); | ||
} | ||
|
||
@Override | ||
public void onFailure(ErrorResponse errorResponse) { | ||
handler.onFailure(errorResponse); | ||
} | ||
}); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...avaSDK/src/main/java/com/loginradius/sdk/models/requestmodels/SsoAuthenticationModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* | ||
* Created by LoginRadius Development Team | ||
Copyright 2019 LoginRadius Inc. All rights reserved. | ||
*/ | ||
|
||
package com.loginradius.sdk.models.requestmodels; | ||
import com.google.gson.annotations.SerializedName; | ||
|
||
// <summary> | ||
// Model Class containing Definition of payload for SSO JWT Cloud API | ||
// </summary> | ||
public class SsoAuthenticationModel { | ||
|
||
|
||
@SerializedName("email") | ||
private String email; | ||
|
||
@SerializedName("username") | ||
private String username ; | ||
|
||
@SerializedName("phone") | ||
private String phone; | ||
|
||
|
||
@SerializedName("password") | ||
private String password; | ||
|
||
|
||
|
||
// <summary> | ||
// user's email | ||
// </summary> | ||
public String getEmail() { | ||
return email; | ||
} | ||
// <summary> | ||
// user's email | ||
// </summary> | ||
public void setEmail(String email) { | ||
this.email = email; | ||
} | ||
// <summary> | ||
// user's username | ||
// </summary> | ||
public String getUserName() { | ||
return username; | ||
} | ||
// <summary> | ||
// user's username | ||
// </summary> | ||
public void setUserName(String username) { | ||
this.username = username; | ||
} | ||
// <summary> | ||
// user's phone | ||
// </summary> | ||
public String getPhone() { | ||
return phone; | ||
} | ||
// <summary> | ||
// user's phone | ||
// </summary> | ||
public void setPhone(String phone) { | ||
this.phone = phone; | ||
} | ||
// <summary> | ||
// Password for the email | ||
// </summary> | ||
public String getPassword() { | ||
return password; | ||
} | ||
// <summary> | ||
// Password for the email | ||
// </summary> | ||
public void setPassword(String password) { | ||
this.password = password; | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...s-JavaSDK/src/main/java/com/loginradius/sdk/models/responsemodels/SsoJwtResponseData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* | ||
* Created by LoginRadius Development Team | ||
Copyright 2019 LoginRadius Inc. All rights reserved. | ||
*/ | ||
|
||
package com.loginradius.sdk.models.responsemodels; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
// <summary> | ||
// Response containing Definition of Jwt Response Data | ||
// </summary> | ||
public class SsoJwtResponseData { | ||
|
||
@SerializedName("signature") | ||
private String signature; | ||
|
||
public String getSignature() { | ||
return signature; | ||
} | ||
|
||
public void setSignature(String signature) { | ||
this.signature = signature; | ||
} | ||
|
||
} |
Oops, something went wrong.