-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c7bf63b
commit 35b8469
Showing
14 changed files
with
313 additions
and
22 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,6 @@ | |
@AllArgsConstructor | ||
public enum FafTokenType { | ||
REGISTRATION, | ||
PASSWORD_RESET | ||
PASSWORD_RESET, | ||
LINK_TO_STEAM | ||
} |
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,68 @@ | ||
package com.faforever.api.user; | ||
|
||
import com.faforever.api.config.FafApiProperties; | ||
import com.faforever.api.config.FafApiProperties.Steam; | ||
import lombok.SneakyThrows; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.http.NameValuePair; | ||
import org.apache.http.client.utils.URLEncodedUtils; | ||
import org.apache.http.message.BasicNameValuePair; | ||
import org.json.JSONObject; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Service | ||
@Slf4j | ||
public class SteamService { | ||
private final FafApiProperties properties; | ||
|
||
public SteamService(FafApiProperties properties) { | ||
this.properties = properties; | ||
} | ||
|
||
String buildLoginUrl(String redirectUrl) { | ||
log.trace("Building steam login url for redirect url: {}", redirectUrl); | ||
|
||
List<NameValuePair> steamArgs = new ArrayList<>(); | ||
steamArgs.add(new BasicNameValuePair("openid.ns", "http://specs.openid.net/auth/2.0")); | ||
steamArgs.add(new BasicNameValuePair("openid.mode", "checkid_setup")); | ||
steamArgs.add(new BasicNameValuePair("openid.return_to", redirectUrl)); | ||
steamArgs.add(new BasicNameValuePair("openid.realm", properties.getSteam().getRealm())); | ||
steamArgs.add(new BasicNameValuePair("openid.identity", "http://specs.openid.net/auth/2.0/identifier_select")); | ||
steamArgs.add(new BasicNameValuePair("openid.claimed_id", "http://specs.openid.net/auth/2.0/identifier_select")); | ||
String queryArgs = URLEncodedUtils.format(steamArgs, "utf8"); | ||
|
||
return String.format(properties.getSteam().getLoginUrlFormat(), queryArgs); | ||
} | ||
|
||
String parseSteamIdFromLoginRedirect(HttpServletRequest request) { | ||
log.trace("Parsing steam id from request: {}", request); | ||
|
||
String identityUrl = request.getParameter("openid.identity"); | ||
return identityUrl.substring(identityUrl.lastIndexOf("/") + 1, identityUrl.length()); | ||
} | ||
|
||
@SneakyThrows | ||
boolean ownsForgedAlliance(String steamId) { | ||
log.debug("Checking whether steamId owns Forged Alliance: {}", steamId); | ||
|
||
Steam steam = properties.getSteam(); | ||
|
||
RestTemplate restTemplate = new RestTemplate(); | ||
List<NameValuePair> steamArgs = new ArrayList<>(); | ||
steamArgs.add(new BasicNameValuePair("key", steam.getApiKey())); | ||
steamArgs.add(new BasicNameValuePair("steamid", steamId)); | ||
steamArgs.add(new BasicNameValuePair("format", "json")); | ||
steamArgs.add(new BasicNameValuePair("appids_filter[0]", steam.getForgedAllianceAppId())); | ||
String queryArgs = URLEncodedUtils.format(steamArgs, "utf8"); | ||
|
||
String response = restTemplate.getForObject(String.format(steam.getGetOwnedGamesUrlFormat(), queryArgs), String.class); | ||
JSONObject result = new JSONObject(response); | ||
|
||
return result.getJSONObject("response").getInt("game_count") > 0; | ||
} | ||
} |
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
Oops, something went wrong.