public class Oauth2
- Object
- Oauth2
OidcClient for new code.Legacy OAuth2 authentication helper. Deprecated as of Codename One 8.0;
new code should use OidcClient instead, which:
- Drives sign-in via the system browser (
SystemBrowser) instead of an in-app WebView. Modern identity providers (Google, Apple, Microsoft, Facebook) refuse to render their sign-in pages inside an embedded WebView and will block this class. - Performs PKCE on every authorization-code flow (mandatory now on most providers).
- Parses the OpenID Connect discovery document so you do not have to hard-code the authorization / token endpoints.
- Verifies the
stateandnonceparameters returned by the server.
This class is preserved as-is for source compatibility but no new functionality will be added. See the Authentication and Identity chapter of the developer guide for a migration recipe.
Nested types
class Oauth2.RefreshTokenRequest |
Fields
public static final String TOKEN = "access_token" |
Constructors
Methods
public static boolean isBackToParent() | Enables going back to the parent form after login is completed |
public static void setBackToParent(boolean aBackToParent) | Enables going back to the parent form after login is completed |
public static Oauth2 fetchSerializedOauth2Request() | |
public static String getExpires() | Returns the expiry for the token received via oauth |
public static boolean handleRedirect(ActionListener callback) | When using the #setUseRedirectForWeb(boolean) option you should call this method at the beginning of your app’s start() method. |
public String authenticate() | Deprecated This method preforms the actual authentication, this method is a blocking method that will display the user the html authentication pages. |
public boolean isUseBrowserWindow() | Checks if this component will use an external web browser window for the login process. |
public void setUseBrowserWindow(boolean useBrowserWindow) | Set this OAuth2 object to use a BrowserWindow for the login process. |
public boolean isUseRedirectForWeb() | Checks wither this Oauth component is configured to use a redirect for Oauth login when running on the web. |
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). |
public Component createAuthComponent(ActionListener al) | This method creates a component which can authenticate. |
public void showAuthentication(ActionListener<ActionEvent> al) | This method shows an authentication for login form |
protected void handleTokenRequestResponse(Map map) | Processes token request responses that are formatted as a JSON object. |
protected void handleTokenRequestResponse(String t) | Processes token request responses that are formatted as HTTP query strings. |
protected void handleRedirectURLParams(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. |
public Oauth2.RefreshTokenRequest refreshToken(String refreshToken) |
Inherited methods
Field details
TOKEN
public static final String TOKEN = "access_token"Constructor details
Oauth2
public Oauth2(String oauth2URL, String clientId, String redirectURI)Parameters
oauth2URLString- the authentication url of the service
clientIdString- the client id that would like to use the service
redirectURIString- the redirect uri
Oauth2
public Oauth2(String oauth2URL, String clientId, String redirectURI, String scope)Parameters
oauth2URLString- the authentication url of the service
clientIdString- the client id that would like to use the service
redirectURIString- the redirect uri
scopeString- the authentication scope
Oauth2
public Oauth2(String oauth2URL, String clientId, String redirectURI, String scope, String tokenRequestURL, String clientSecret)Parameters
oauth2URLString- the authentication url of the service
clientIdString- the client id that would like to use the service
redirectURIString- the redirect uri
scopeString- the authentication scope
tokenRequestURLString- Not documented.
clientSecretString- the client secret
Oauth2
public Oauth2(String oauth2URL, String clientId, String redirectURI, String scope, String tokenRequestURL, String clientSecret, Hashtable additionalParams)Parameters
oauth2URLString- the authentication url of the service
clientIdString- the client id that would like to use the service
redirectURIString- the redirect uri
scopeString- the authentication scope
tokenRequestURLString- Not documented.
clientSecretString- the client secret
additionalParamsHashtable- hashtable of additional parameters to the authentication request
Method details
isBackToParent
public static boolean isBackToParent()Returns
setBackToParent
public static void setBackToParent(boolean aBackToParent)Parameters
aBackToParentboolean- the backToParent to set
fetchSerializedOauth2Request
public static Oauth2 fetchSerializedOauth2Request()getExpires
public static String getExpires()Returns
handleRedirect
public static boolean handleRedirect(ActionListener callback)#setUseRedirectForWeb(boolean) option you should call this method at the beginning of your app’s
start() 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
callbackActionListener- a listener that will receive at its source either a token for the service or an exception in case of a failure
Returns
authenticate
public String authenticate()Returns
Throws
IOException- the method will throw an IOException if something went wrong in the communication.
isUseBrowserWindow
public boolean isUseBrowserWindow()Returns
setUseBrowserWindow
public void setUseBrowserWindow(boolean useBrowserWindow)Set this OAuth2 object to use a BrowserWindow for 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
useBrowserWindowboolean- True to use a browser window for the login process.
isUseRedirectForWeb
public boolean isUseRedirectForWeb()Returns
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
redirectboolean- Set to true to use a redirect for Oauth login instead of an iframe when running on the web.
createAuthComponent
public Component createAuthComponent(ActionListener al)Parameters
alActionListener- a listener that will receive at its source either a token for the service or an exception in case of a failure
Returns
showAuthentication
public void showAuthentication(ActionListener<ActionEvent> al)Parameters
alActionListener<ActionEvent>- a listener that will receive at its source either a token for the service or an exception in case of a failure
handleTokenRequestResponse
protected void handleTokenRequestResponse(Map map)Parameters
mapMap- Parsed JSON object of response.
handleTokenRequestResponse
protected void handleTokenRequestResponse(String t)Parameters
tString- The query string.
handleRedirectURLParams
protected void handleRedirectURLParams(Map params)Parameters
paramsMap- Parsed query parameters passed to the redirect URL.
refreshToken
public Oauth2.RefreshTokenRequest refreshToken(String refreshToken)