public class YfyWebAuth extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
YfyWebAuth.BadRequestException
Thrown when the parameters passed to your redirect URI are not well-formed.
|
static class |
YfyWebAuth.BadStateException
Thrown if all the parameters to your redirect URI are well-formed, but there's no CSRF token
in the session.
|
static class |
YfyWebAuth.CsrfException
Thrown if the given 'state' parameter doesn't contain the expected CSRF token.
|
static class |
YfyWebAuth.Request
OAuth web-based authorization flow request.
|
| Constructor and Description |
|---|
YfyWebAuth(YfyRequestConfig requestConfig)
Creates a new instance that will perform the OAuth2 authorization flow using the given OAuth
request configuration.
|
| Modifier and Type | Method and Description |
|---|---|
String |
authorize(YfyWebAuth.Request request)
Starts authorization and returns a "authorization URL" on the Fangcloud website that gives the
lets the user grant your app access to their Fangcloud account.
|
YfyAuthFinish |
finishFromCode(String code)
Call this after the user has visited the authorization URL and copy/pasted the authorization
code that Fangcloud gave them.
|
YfyAuthFinish |
finishFromRedirect(String redirectUri,
YfySessionStore sessionStore,
Map<String,String[]> params)
Call this after the user has visited the authorization URL and Fangcloud has redirected them
back to you at the redirect URI.
|
static YfyWebAuth.Request.Builder |
newRequestBuilder()
Returns a new request builder with default values (e.g. no redirect).
|
YfyAuthFinish |
passwordLogin(String username,
String password)
The method is used by password model user, the user is not the Fangcloud user.
|
public YfyWebAuth(YfyRequestConfig requestConfig)
requestConfig - HTTP request configuration, never null.public String authorize(YfyWebAuth.Request request)
If a redirect URI was specified (YfyWebAuth.Request.Builder.withRedirectUri(java.lang.String, com.fangcloud.sdk.YfySessionStore)), then users
will be redirected to the redirect URI after completing the authorization flow. Call finishFromRedirect(java.lang.String, com.fangcloud.sdk.YfySessionStore, java.util.Map<java.lang.String, java.lang.String[]>) with the query parameters received from the redirect.
If no redirect URI was specified (YfyWebAuth.Request.Builder.withNoRedirect()), then users who
grant access will be shown an "authorization code". The user must copy/paste the
authorization code back into your app, at which point you can call finishFromCode(String) to get an access token.
request - OAuth 2.0 web-based authorization flow request configurationpublic YfyAuthFinish finishFromRedirect(String redirectUri, YfySessionStore sessionStore, Map<String,String[]> params) throws YfyException, YfyWebAuth.BadRequestException, YfyWebAuth.BadStateException, YfyWebAuth.CsrfException
redirectUri - The original redirect URI used by authorize(com.fangcloud.sdk.auth.YfyWebAuth.Request), never null.sessionStore - Session store used by authorize(com.fangcloud.sdk.auth.YfyWebAuth.Request) to store CSRF tokens, never
null.params - The query parameters on the GET request to your redirect URI, never null.YfyWebAuth.BadRequestException - If the redirect request is missing required query parameters,
contains duplicate parameters, or includes mutually exclusive parameters (e.g. "error" and "code").YfyWebAuth.BadStateException - If the CSRF token retrieved from sessionStore is null or malformed.YfyWebAuth.CsrfException - If the CSRF token passed in params does not match the CSRF
token from sessionStore. This implies the redirect request may be forged.YfyException - If an error occurs communicating with Fangcloud.public YfyAuthFinish finishFromCode(String code) throws YfyException
code - The authorization code shown to the user when they clicked "Allow" on the
authorization, page on the Fangcloud website, never null.YfyException - if an error occurs communicating with Fangcloud.public YfyAuthFinish passwordLogin(String username, String password) throws YfyException
username - Special username which open platform team gives to youpassword - Special password which open platform team gives to youYfyExceptionpublic static YfyWebAuth.Request.Builder newRequestBuilder()
Copyright © 2018 YiFangYun. All rights reserved.