Class Login

java.lang.Object
com.codename1.social.Login
Direct Known Subclasses:
FacebookConnect, GoogleConnect

public abstract class Login extends Object
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.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    addScopes(String... scopes)
    Adds the given scopes to the OAuth2 login request.
    Connects to the login service asynchronously, automatically logging in if not yet logged in.
    protected Oauth2
    Creates the oauth2 to be used to login in case no native login is available for this service.
    void
    Logs in the user.
    void
    Initiates login using the given single-use callback.
    void
    Logs out the current user
    The AccessToken of this service
    abstract boolean
    Returns true if this service supports native login.
    boolean
    A flag used by the javascript port to indicate that the login will use a redirect for the prompt instead of a popup.
    boolean
    Indicates if the user is currently logged in
    boolean
    Indicates if the user is currently logged in.
    void
    Logs in the current user natively.
    void
    Logs out the current user natively.
    void
    Sets the Login access token
    void
    Sets the login callback that will receive event callback notification from the API
    void
    The client id (appid) which asks to connect
    void
    The client secret
    void
    setOauth2URL(String oauth2URL)
    The oauth2 URL
    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.
    void
    setRedirectURI(String redirectURI)
    The redirect URI
    void
    The authentication scope
    void
    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
    Returns true if the previous granted access token is still valid otherwise false.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    Modifier and Type
    Method
    Description
    protected Object
     
    boolean
    Indicates whether some other object is "equal to" this one.
    final Class
    Returns the runtime class of an object.
    int
    Returns a hash code value for the object.
    final void
    Wakes up a single thread that is waiting on this object's monitor.
    final void
    Wakes up all threads that are waiting on this object's monitor.
    Returns a string representation of the object.
    final void
    Causes current thread to wait until another thread invokes the method or the method for this object.
    final void
    wait(long timeout)
    Causes current thread to wait until either another thread invokes the method or the method for this object, or a specified amount of time has elapsed.
    final void
    wait(long timeout, int nanos)
    Causes current thread to wait until another thread invokes the method or the method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.
  • Constructor Details

    • Login

      public Login()
  • Method Details

    • addScopes

      public Login addScopes(String... scopes)

      Adds the given scopes to the OAuth2 login request.

      Parameters
      • scopes: Scopes to add.
      Returns

      Self for chaining.

      Since

      7.0

      See also
      • #setScope(java.lang.String)
    • 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.

      Since

      7.0

    • doLogin

      public void doLogin(LoginCallback callback)

      Initiates login using the given single-use callback.

      Parameters
      • callback: Callback to be called if login succeeds or fails.
      Since

      7.0

    • 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 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
      Throws:
      IOException
    • validateToken

      protected abstract boolean validateToken(String token)

      Returns true if the previous granted access token is still valid otherwise false.

      Parameters
      • token: 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
      • lc: @param lc 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

      Parameters
      • clientId
    • setClientSecret

      public void setClientSecret(String secret)

      The client secret

      Parameters
      • clientSecret
    • setRedirectURI

      public void setRedirectURI(String redirectURI)

      The redirect URI

      Parameters
      • redirectURI
    • 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
      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

      Since

      7.0

    • 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
      • preferRedirectPrompt: the preferRedirectPrompt to set
      Since

      7.0