public abstract class Login
- Object
- Login
Known subtypesAppleSignIn, Auth0Connect, FacebookConnect, GoogleConnect, MicrosoftConnect
The Login abstract base class is used to simplify Oauth2 authentications
services.
Services can override the default Oauth2 web login and offers the native login
experience.
Constructors
public Login() |
Methods
public Login addScopes(String... scopes) | Adds the given scopes to the OAuth2 login request. |
public AsyncResource<Login> connect() | Connects to the login service asynchronously, automatically logging in if not yet logged in. |
public void doLogin(LoginCallback callback) | Initiates login using the given single-use callback. |
public void doLogin() | Logs in the user. |
public void doLogout() | Logs out the current user |
public boolean isUserLoggedIn() | Indicates if the user is currently logged in |
public boolean nativeIsLoggedIn() | Indicates if the user is currently logged in. |
public void nativelogin() | Logs in the current user natively. |
public void nativeLogout() | Logs out the current user natively. |
public abstract boolean isNativeLoginSupported() | Returns true if this service supports native login. |
public AccessToken getAccessToken() | The AccessToken of this service |
public void setAccessToken(AccessToken token) | Sets the Login access token |
public void validateToken()
throws IOException | This method tries to validate the last access token if exists, if the last token is not valid anymore it will try to login the user in order to get a fresh token The method blocks until a valid token has been granted |
protected abstract boolean validateToken(String token) | Returns true if the previous granted access token is still valid otherwise false. |
public void setCallback(LoginCallback lc) | Sets the login callback that will receive event callback notification from the API |
public void setClientId(String id) | The client id (appid) which asks to connect |
public void setClientSecret(String secret) | The client secret |
public void setRedirectURI(String redirectURI) | The redirect URI |
public void setScope(String scope) | The authentication scope |
public void setOauth2URL(String oauth2URL) | The oauth2 URL |
protected Oauth2 createOauth2() | Creates the oauth2 to be used to login in case no native login is available for this service. |
public boolean isPreferRedirectPrompt() | A flag used by the javascript port to indicate that the login will use a redirect for the prompt instead of a popup. |
public void setPreferRedirectPrompt(boolean preferRedirectPrompt) | A flag used by the javascript port to indicate that the login will use a redirect for the prompt instead of a popup. |
Inherited methods
Constructor details
Login
public Login()Method details
addScopes
public Login addScopes(String... scopes)Adds the given scopes to the OAuth2 login request.
Parameters
scopesString...- Scopes to add.
Returns
Self for chaining.
See also
connect
public AsyncResource<Login> connect()Connects to the login service asynchronously, automatically logging in
if not yet logged in.
Returns
AsyncResource that can be monitored for completion.
doLogin
public void doLogin(LoginCallback callback)Initiates login using the given single-use callback.
Parameters
callbackLoginCallback- Callback to be called if login succeeds or fails.
doLogin
public void doLogin()Logs in the user.
If the service has a native login it will try to use that, otherwise an
Oauth2 web login will be used.
doLogout
public void doLogout()Logs out the current user
isUserLoggedIn
public boolean isUserLoggedIn()Indicates if the user is currently logged in
Returns
true if logged in
nativeIsLoggedIn
public boolean nativeIsLoggedIn()Indicates if the user is currently logged in.
Subclasses that uses a native sdk to login/logout should override this
method.
Returns
true if logged in
nativelogin
public void nativelogin()Logs in the current user natively.
Subclasses that uses a native sdk to login/logout should override this
method.
nativeLogout
public void nativeLogout()Logs out the current user natively.
Subclasses that uses a native sdk to login/logout should override this
method.
isNativeLoginSupported
public abstract boolean isNativeLoginSupported()Returns true if this service supports native login.
If implementation returns true here, the nativelogin, nativelogout,
nativeIsLoggedIn should be implemented
Returns
true if the service supports native login
getAccessToken
public AccessToken getAccessToken()The AccessToken of this service
Returns
the token
setAccessToken
public void setAccessToken(AccessToken token)Sets the Login access token
validateToken
public void validateToken()
throws IOExceptionThis method tries to validate the last access token if exists, if the
last token is not valid anymore it will try to login the user in order to
get a fresh token
The method blocks until a valid token has been granted
Throws
validateToken
protected abstract boolean validateToken(String token)Returns true if the previous granted access token is still valid otherwise
false.
Parameters
tokenString- the access token to check
Returns
true of the token is valid
setCallback
public void setCallback(LoginCallback lc)Sets the login callback that will receive event callback notification
from the API
Parameters
lcLoginCallback- the login callback or null to remove the existing login callback
setClientId
public void setClientId(String id)The client id (appid) which asks to connect
setClientSecret
public void setClientSecret(String secret)The client secret
setRedirectURI
public void setRedirectURI(String redirectURI)The redirect URI
setScope
public void setScope(String scope)The authentication scope
setOauth2URL
public void setOauth2URL(String oauth2URL)The oauth2 URL
createOauth2
protected Oauth2 createOauth2()Creates the oauth2 to be used to login in case no native login is available
for this service.
Returns
the Oauth2 to be used to login if no native login available and
on the simulator
isPreferRedirectPrompt
public boolean isPreferRedirectPrompt()A flag used by the javascript port to indicate that the login will use a redirect
for the prompt instead of a popup. On the web, a redirect is usually better UX
but it can be problematic since it involves leaving the app, and reloading it
after the login.
Returns
the preferRedirectPrompt
setPreferRedirectPrompt
public void setPreferRedirectPrompt(boolean preferRedirectPrompt)A flag used by the javascript port to indicate that the login will use a redirect
for the prompt instead of a popup. On the web, a redirect is usually better UX
but it can be problematic since it involves leaving the app, and reloading it
after the login.
Parameters
preferRedirectPromptboolean- the preferRedirectPrompt to set