com.google.appengine.api.users.dev.LocalOAuthAuthorizeTokenServlet Maven / Gradle / Ivy
/*
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.appengine.api.users.dev;
import com.google.appengine.repackaged.com.google.common.html.HtmlEscapers;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* {@code LocalOAuthAuthorizeTokenServlet} is the servlet responsible for
* implementing the token authorization step of the fake OAuth authentication
* flow provided by the Development AppServer.
*
* This serlvet will redirect to the URL specified in the 'oauth_callback'
* parameter after access is granted. It does not currently support callback
* URLs provided during the request token acquisition step.
*
*/
public class LocalOAuthAuthorizeTokenServlet extends HttpServlet {
private static final long serialVersionUID = 1789085416447898108L;
private static final String BLUE_BOX_STYLE = "width: 20em;"
+ "margin: 1em auto;"
+ "text-align: left;"
+ "padding: 0 2em 1.25em 2em;"
+ "background-color: #d6e9f8;"
+ "font: 13px sans-serif;"
+ "border: 2px solid #67a7e3";
// TODO: Validate that the token exists.
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String oauthCallback = req.getParameter("oauth_callback");
if (oauthCallback == null) {
oauthCallback = "";
}
// TODO: Move to a JSP?
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
out.println("");
out.println("
");
out.println("");
out.println("");
out.println("");
}
// TODO: Mark the token as approved.
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String oauthCallback = req.getParameter("oauth_callback");
if (oauthCallback != null && oauthCallback.length() > 0) {
resp.sendRedirect(oauthCallback);
} else {
// TODO: Move to a JSP?
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
out.println("");
out.println("");
out.printf("\n", BLUE_BOX_STYLE);
out.println("OAuth Access Granted
");
out.println("");
out.println("");
out.println("");
}
}
}