Class Oauth2
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSimple constructorSimple constructorOauth2(String oauth2URL, String clientId, String redirectURI, String scope, String tokenRequestURL, String clientSecret) Simple constructorOauth2(String oauth2URL, String clientId, String redirectURI, String scope, String tokenRequestURL, String clientSecret, Hashtable additionalParams) Simple constructor -
Method Summary
Modifier and TypeMethodDescriptionThis method preforms the actual authentication, this method is a blocking method that will display the user the html authentication pages.This method creates a component which can authenticate.static Oauth2static StringReturns the expiry for the token received via oauthstatic booleanhandleRedirect(ActionListener callback) When using the#setUseRedirectForWeb(boolean)option you should call this method at the beginning of your app'sstart()method.protected voidhandleRedirectURLParams(Map params) Method that can be overridden by subclasses to intercept parameters extracted from the redirect URL when the login flow reaches the redirect URL.protected voidProcesses token request responses that are formatted as HTTP query strings.protected voidProcesses token request responses that are formatted as a JSON object.static booleanEnables going back to the parent form after login is completedbooleanChecks if this component will use an external web browser window for the login process.booleanChecks wither this Oauth component is configured to use a redirect for Oauth login when running on the web.refreshToken(String refreshToken) static voidsetBackToParent(boolean aBackToParent) Enables going back to the parent form after login is completedvoidsetUseBrowserWindow(boolean useBrowserWindow) Set this OAuth2 object to use aBrowserWindowfor the login process.voidsetUseRedirectForWeb(boolean redirect) Sets thisOAuth2 object to use a redirect for login instead of an iframe when running on the Web (via the Javascript port).voidThis method shows an authentication for login form
-
Field Details
-
TOKEN
- See Also:
-
-
Constructor Details
-
Oauth2
-
Oauth2
-
Oauth2
public Oauth2(String oauth2URL, String clientId, String redirectURI, String scope, String tokenRequestURL, String clientSecret) Simple constructor
Parameters
-
oauth2URL: the authentication url of the service -
clientId: the client id that would like to use the service -
redirectURI: the redirect uri -
scope: the authentication scope -
clientSecret: the client secret
-
-
Oauth2
public Oauth2(String oauth2URL, String clientId, String redirectURI, String scope, String tokenRequestURL, String clientSecret, Hashtable additionalParams) Simple constructor
Parameters
-
oauth2URL: the authentication url of the service -
clientId: the client id that would like to use the service -
redirectURI: the redirect uri -
scope: the authentication scope -
clientSecret: the client secret -
additionalParams: @param additionalParams hashtable of additional parameters to the authentication request
-
-
-
Method Details
-
isBackToParent
public static boolean isBackToParent()Enables going back to the parent form after login is completed
Returns
the backToParent
-
setBackToParent
public static void setBackToParent(boolean aBackToParent) Enables going back to the parent form after login is completed
Parameters
aBackToParent: the backToParent to set
-
fetchSerializedOauth2Request
-
getExpires
Returns the expiry for the token received via oauth
Returns
the expires argument for the token
-
handleRedirect
When using the
#setUseRedirectForWeb(boolean)option you should call this method at the beginning of your app'sstart()method. If the app was loaded as a result of redirecting from an Oauth login, then this method will handle the login and will call the callback method on complete.Parameters
callback: @param callback a listener that will receive at its source either a token for the service or an exception in case of a failure
Returns
- Returns:
True the redirect was handled. False if it was not handled. If this returns true, then you should just return from the start() method, and instead handle control flow in your callback.
Since
7.0
See also
-
#setUseRedirectForWeb(boolean)
-
#isUseRedirectForWeb()
-
-
authenticate
This method preforms the actual authentication, this method is a blocking method that will display the user the html authentication pages.
Returns
- Returns:
the method if passes authentication will return the access token or null if authentication failed.
Throws
IOException: @throws IOException the method will throw an IOException if something went wrong in the communication.
Deprecated
-
isUseBrowserWindow
public boolean isUseBrowserWindow()Checks if this component will use an external web browser window for the login process.
Returns
True if this component will use an external web browser window.
Since
7.0
-
setUseBrowserWindow
public void setUseBrowserWindow(boolean useBrowserWindow) Set this OAuth2 object to use a
BrowserWindowfor the login process. You can set the global default via the "oauth2.useBrowserWindow" display property with either a "true" or "false" value.When this property is set, the login prompt will be displayed in a separate Window containing a web browser on the desktop. Platforms that don't have windows (e.g. iOS/Android) will fall back to a separate Form with a webview).
Parameters
useBrowserWindow: True to use a browser window for the login process.
Since
7.0
-
isUseRedirectForWeb
public boolean isUseRedirectForWeb()Checks wither this Oauth component is configured to use a redirect for Oauth login when running on the web.
Returns
True if this component will use a redirect for Oauth login.
Since
7.0
See also
-
#setUseRedirectForWeb(boolean)
-
#handleRedirect(com.codename1.ui.events.ActionListener)
-
-
setUseRedirectForWeb
public void setUseRedirectForWeb(boolean redirect) Sets thisOAuth2 object to use a redirect for login instead of an iframe when running on the Web (via the Javascript port). Some Oauth providers won't work inside an iframe.
Using this option will cause the browser to navigate away from the app to go to the login page. The Oauth login will redirect back to the app after login is complete.
Warning: If the user has unsaved changes in the app, navigating away from the app may cause them to lose their changes. You should provide a warning, or confirmation prompt for the user in such cases. The usual onbeforeunload handler is disabled when using this action so the user won't receive any warnings other than what you explicitly prompt.
Parameters
redirect: Set to true to use a redirect for Oauth login instead of an iframe when running on the web.
Since
7.0
See also
-
#isUseRedirectForWeb()
-
#handleRedirect(com.codename1.ui.events.ActionListener)
-
createAuthComponent
This method creates a component which can authenticate. You will receive either the authentication key or an Exception object within the ActionListener callback method.
Parameters
al: @param al a listener that will receive at its source either a token for the service or an exception in case of a failure
Returns
- Returns:
- a component that should be displayed to the user in order to perform the authentication
-
showAuthentication
This method shows an authentication for login form
Parameters
al: @param al a listener that will receive at its source either a token for the service or an exception in case of a failure
-
handleTokenRequestResponse
Processes token request responses that are formatted as a JSON object. May be overridden by subclasses, but subclass implementations should call super.handleTokenRequestResponse() so that the default implementation can parse out the token, expires, and refreshToken fields.
Parameters
map: Parsed JSON object of response.
Since
7.0
-
handleTokenRequestResponse
Processes token request responses that are formatted as HTTP query strings. May be overridden by subclass, but subclass implementations should call super.handleTokenRequestResponse() so that the default implementation can parse out the token, expires, and refreshToken fields.
Parameters
t: The query string.
Since
7.0
-
handleRedirectURLParams
Method that can be overridden by subclasses to intercept parameters extracted from the redirect URL when the login flow reaches the redirect URL. This will give subclasses an opportunity to parse out special information that the OAuth2 service provides in the callback.
Parameters
params: Parsed query parameters passed to the redirect URL.
-
refreshToken
-