com.pryv.auth.AuthController Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commons Show documentation
Show all versions of commons Show documentation
Common library shared among Java and Android.
The newest version!
package com.pryv.auth;
import com.pryv.model.Permission;
import com.pryv.utils.Logger;
import java.util.List;
/**
* High-level used to Authenticate the user. Upon success, provides a Connection
* with the appropriate username and token.
*/
public class AuthController {
private String requestingAppId;
private List permissions;
private AuthView view;
private AuthModel model;
// optional
private String language = "en";
private String returnURL = "";
private Logger logger = Logger.getInstance();
/**
*
* @param pRequestingAppId
* Your app's identifier
* @param pPermissions
* Array of permission request objects
* @param pLang
* optional: The two-letter ISO (639-1) code of the language in
* which to display user instructions, if possible. Default: en.
* @param pReturnURL
* optional: The URL to redirect the user to after auth completes
* @param pView
* the view in which the URL for login is displayed
*/
public AuthController(String pRequestingAppId, List pPermissions, String pLang, String pReturnURL,
AuthView pView) {
requestingAppId = pRequestingAppId;
permissions = pPermissions;
if (pLang != null) {
language = pLang;
}
if (pReturnURL != null) {
returnURL = pReturnURL;
}
view = pView;
}
public void signIn() {
model = new AuthModel(this, requestingAppId, permissions, language, returnURL);
model.startLogin();
}
public void onSuccess(String username, String token) {
view.onAuthSuccess(username, token);
// acquire ref to new Connection, instanciated
}
public void onError(String message) {
logger.log("AuthControllerImpl: failure: message=" + message);
view.onAuthError("AuthController: failure: message=" + message);
}
public void onRefused(int reasonId, String message, String detail) {
logger.log("AuthControllerImpl: refused: reasonId=" + reasonId + ", message=" + message + ", detail=" + detail);
view.onAuthRefused(reasonId, message, detail);
}
public void displayLoginView(String url) {
view.displayLoginView(url);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy