-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
loginbuddy now proxies calls to the providers userinfo endpoint if th…
…ey are made within 60s after issuing the token
- Loading branch information
1 parent
5b2708d
commit 0d2090a
Showing
10 changed files
with
129 additions
and
33 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
net.loginbuddy.common/src/main/java/net/loginbuddy/common/util/ParameterValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
net.loginbuddy.service/src/main/java/net/loginbuddy/service/resources/Userinfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package net.loginbuddy.service.resources; | ||
|
||
import java.io.IOException; | ||
import java.util.Base64; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import net.loginbuddy.common.api.HttpHelper; | ||
import net.loginbuddy.common.cache.LoginbuddyCache; | ||
import net.loginbuddy.common.config.Constants; | ||
import net.loginbuddy.common.util.MsgResponse; | ||
import net.loginbuddy.common.util.ParameterValidator; | ||
import net.loginbuddy.common.util.ParameterValidatorResult; | ||
import net.loginbuddy.service.config.LoginbuddyConfig; | ||
import net.loginbuddy.service.config.ProviderConfig; | ||
import net.loginbuddy.service.server.Overlord; | ||
import org.json.simple.JSONObject; | ||
import org.json.simple.parser.JSONParser; | ||
import org.json.simple.parser.ParseException; | ||
import sun.misc.BASE64Decoder; | ||
|
||
public class Userinfo extends Overlord { | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||
|
||
ParameterValidatorResult accessToken = ParameterValidator.getSingleValue(request.getParameterValues("access_token")); | ||
String authorizationHeader = request.getHeader("Authorization"); | ||
|
||
String hint; | ||
String[] token = HttpHelper.extractAccessToken(accessToken, authorizationHeader).split("."); | ||
if(token.length == 3) { | ||
hint = token[2]; | ||
} else { | ||
hint = accessToken.getValue(); | ||
} | ||
|
||
MsgResponse msg; | ||
JSONObject apis = (JSONObject)LoginbuddyCache.getInstance().get(hint); | ||
if(apis == null) { | ||
msg = new MsgResponse(); | ||
msg.setStatus(400); | ||
msg.setContentType("application/json"); | ||
msg.setMsg(HttpHelper.getErrorAsJson("invalid_request", "the given token is unknown").toJSONString()); | ||
} else { | ||
msg = HttpHelper.getAPI(accessToken.getValue(), (String)apis.get(Constants.USERINFO_ENDPOINT.getKey())); | ||
} | ||
|
||
response.setStatus(msg.getStatus()); | ||
response.setContentType(msg.getContentType()); | ||
response.getWriter().write(msg.getMsg()); | ||
} | ||
|
||
@Override | ||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | ||
doGet(req, resp); | ||
} | ||
} |
19 changes: 0 additions & 19 deletions
19
net.loginbuddy.service/src/main/java/net/loginbuddy/service/server/Userinfo.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters