public class Oauth2 extends Object
Modifier and Type | Class and Description |
---|---|
class |
Oauth2.RefreshTokenRequest |
Constructor and Description |
---|
Oauth2(String oauth2URL,
String clientId,
String redirectURI)
Simple constructor
|
Oauth2(String oauth2URL,
String clientId,
String redirectURI,
String scope)
Simple constructor
|
Oauth2(String oauth2URL,
String clientId,
String redirectURI,
String scope,
String tokenRequestURL,
String clientSecret)
Simple constructor
|
Oauth2(String oauth2URL,
String clientId,
String redirectURI,
String scope,
String tokenRequestURL,
String clientSecret,
Hashtable additionalParams)
Simple constructor
|
Modifier and Type | Method and Description |
---|---|
String |
authenticate()
Deprecated.
use createAuthComponent or showAuthentication which work
asynchronously and adapt better to different platforms
|
Component |
createAuthComponent(ActionListener al)
This method creates a component which can authenticate.
|
static Oauth2 |
fetchSerializedOauth2Request() |
static String |
getExpires()
Returns the expiry for the token received via oauth
|
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. |
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.
|
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.
|
static boolean |
isBackToParent()
Enables going back to the parent form after login is completed
|
boolean |
isUseBrowserWindow()
Checks if this component will use an external web browser window for the login process.
|
boolean |
isUseRedirectForWeb()
Checks wither this Oauth component is configured to use a redirect for Oauth login when running on the web.
|
Oauth2.RefreshTokenRequest |
refreshToken(String refreshToken) |
static void |
setBackToParent(boolean aBackToParent)
Enables going back to the parent form after login is completed
|
void |
setUseBrowserWindow(boolean useBrowserWindow)
Set this OAuth2 object to use a
BrowserWindow for the login process. |
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).
|
void |
showAuthentication(ActionListener al)
This method shows an authentication for login form
|
public static final String TOKEN
public Oauth2(String oauth2URL, String clientId, String redirectURI)
oauth2URL
- the authentication url of the serviceclientId
- the client id that would like to use the serviceredirectURI
- the redirect uripublic Oauth2(String oauth2URL, String clientId, String redirectURI, String scope)
oauth2URL
- the authentication url of the serviceclientId
- the client id that would like to use the serviceredirectURI
- the redirect uriscope
- the authentication scopepublic Oauth2(String oauth2URL, String clientId, String redirectURI, String scope, String tokenRequestURL, String clientSecret)
oauth2URL
- the authentication url of the serviceclientId
- the client id that would like to use the serviceredirectURI
- the redirect uriscope
- the authentication scopeclientSecret
- the client secretpublic Oauth2(String oauth2URL, String clientId, String redirectURI, String scope, String tokenRequestURL, String clientSecret, Hashtable additionalParams)
oauth2URL
- the authentication url of the serviceclientId
- the client id that would like to use the serviceredirectURI
- the redirect uriscope
- the authentication scopeclientSecret
- the client secretadditionalParams
- hashtable of additional parameters to the
authentication requestpublic static boolean isBackToParent()
public static void setBackToParent(boolean aBackToParent)
aBackToParent
- the backToParent to setpublic static Oauth2 fetchSerializedOauth2Request()
public static String getExpires()
public String authenticate()
IOException
- the method will throw an IOException if something
went wrong in the communication.public void setUseBrowserWindow(boolean useBrowserWindow)
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).
useBrowserWindow
- True to use a browser window for the login process.public boolean isUseBrowserWindow()
public void setUseRedirectForWeb(boolean redirect)
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.
redirect
- Set to true to use a redirect for Oauth login instead of an iframe when running on the web.isUseRedirectForWeb()
,
handleRedirect(com.codename1.ui.events.ActionListener)
public boolean isUseRedirectForWeb()
setUseRedirectForWeb(boolean)
,
handleRedirect(com.codename1.ui.events.ActionListener)
public Component createAuthComponent(ActionListener al)
al
- a listener that will receive at its source either a token for
the service or an exception in case of a failurepublic 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.callback
- a listener that will receive at its source either a token for
the service or an exception in case of a failuresetUseRedirectForWeb(boolean)
,
isUseRedirectForWeb()
public void showAuthentication(ActionListener al)
al
- a listener that will receive at its source either a token for
the service or an exception in case of a failureprotected void handleTokenRequestResponse(Map map)
map
- Parsed JSON object of response.protected void handleTokenRequestResponse(String t)
t
- The query string.protected void handleRedirectURLParams(Map params)
params
- Parsed query parameters passed to the redirect URL.public Oauth2.RefreshTokenRequest refreshToken(String refreshToken)