我正在尝试用Java实现Google的OAuth2流程:
// Load client secrets.
InputStream in = Application.class.getResourceAsStream("/client_secret.json");
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
// Build flow and trigger user authorization request.
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
GoogleNetHttpTransport.newTrustedTransport(),
JacksonFactory.getDefaultInstance(),
clientSecrets,
Arrays.asList(GmailScopes.GMAIL_LABELS)
)
.setAccessType("offline")
.build();
String uri = flow
.newAuthorizationUrl()
.setRedirectUri("http://example.com/#/oauth2callback")
.build();
创建uri
字符串后,我会尝试导航到它,希望在身份验证过程后,我会被重定向到http://example.com/#/oauth2callback
。但谷歌提示错误说:
Invalid parameter value for redirect_uri: Fragment not allowed
这意味着我无法在我的重定向URI中使用#
(据我所知)。它有什么办法吗?如何设置包含#
的重定向URI?