-
-
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.
- Loading branch information
Showing
14 changed files
with
217 additions
and
19 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
42 changes: 42 additions & 0 deletions
42
src/main/java/net/raphimc/minecraftauth/responsehandler/DebugResponseHandler.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,42 @@ | ||
/* | ||
* This file is part of MinecraftAuth - https://github.com/RaphiMC/MinecraftAuth | ||
* Copyright (C) 2023 RK_01/RaphiMC and contributors | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package net.raphimc.minecraftauth.responsehandler; | ||
|
||
import org.apache.http.HttpEntity; | ||
import org.apache.http.HttpResponse; | ||
import org.apache.http.StatusLine; | ||
import org.apache.http.client.HttpResponseException; | ||
import org.apache.http.client.ResponseHandler; | ||
import org.apache.http.util.EntityUtils; | ||
|
||
import java.io.IOException; | ||
|
||
public class DebugResponseHandler implements ResponseHandler<String> { | ||
|
||
@Override | ||
public String handleResponse(HttpResponse response) throws IOException { | ||
final StatusLine statusLine = response.getStatusLine(); | ||
final HttpEntity entity = response.getEntity(); | ||
final String body = entity == null ? null : EntityUtils.toString(entity); | ||
if (statusLine.getStatusCode() >= 300) { | ||
throw new HttpResponseException(statusLine.getStatusCode(), body); | ||
} | ||
return body; | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/net/raphimc/minecraftauth/responsehandler/MinecraftResponseHandler.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,52 @@ | ||
/* | ||
* This file is part of MinecraftAuth - https://github.com/RaphiMC/MinecraftAuth | ||
* Copyright (C) 2023 RK_01/RaphiMC and contributors | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package net.raphimc.minecraftauth.responsehandler; | ||
|
||
import com.google.gson.JsonObject; | ||
import net.raphimc.minecraftauth.responsehandler.exception.MinecraftResponseException; | ||
import net.raphimc.minecraftauth.util.JsonUtil; | ||
import org.apache.http.HttpEntity; | ||
import org.apache.http.HttpResponse; | ||
import org.apache.http.StatusLine; | ||
import org.apache.http.client.HttpResponseException; | ||
import org.apache.http.client.ResponseHandler; | ||
import org.apache.http.entity.ContentType; | ||
import org.apache.http.util.EntityUtils; | ||
|
||
import java.io.IOException; | ||
|
||
public class MinecraftResponseHandler implements ResponseHandler<String> { | ||
|
||
@Override | ||
public String handleResponse(HttpResponse response) throws IOException { | ||
final StatusLine statusLine = response.getStatusLine(); | ||
final HttpEntity entity = response.getEntity(); | ||
final String body = entity == null ? null : EntityUtils.toString(entity); | ||
if (statusLine.getStatusCode() >= 300) { | ||
if (body != null && ContentType.getOrDefault(entity).getMimeType().equals(ContentType.APPLICATION_JSON.getMimeType())) { | ||
final JsonObject obj = (JsonObject) JsonUtil.parseString(body); | ||
if (obj.has("error") && obj.has("errorMessage")) { | ||
throw new MinecraftResponseException(statusLine.getStatusCode(), obj.get("error").getAsString(), obj.get("errorMessage").getAsString()); | ||
} | ||
} | ||
throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase()); | ||
} | ||
return body; | ||
} | ||
|
||
} |
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
34 changes: 34 additions & 0 deletions
34
.../java/net/raphimc/minecraftauth/responsehandler/exception/MinecraftResponseException.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,34 @@ | ||
/* | ||
* This file is part of MinecraftAuth - https://github.com/RaphiMC/MinecraftAuth | ||
* Copyright (C) 2023 RK_01/RaphiMC and contributors | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package net.raphimc.minecraftauth.responsehandler.exception; | ||
|
||
import lombok.Getter; | ||
import org.apache.http.client.HttpResponseException; | ||
|
||
@Getter | ||
public class MinecraftResponseException extends HttpResponseException { | ||
|
||
private final String error; | ||
|
||
public MinecraftResponseException(final int statusCode, final String error, final String reasonPhrase) { | ||
super(statusCode, reasonPhrase + ", minecraft error: " + error); | ||
|
||
this.error = error; | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/net/raphimc/minecraftauth/responsehandler/exception/MsaResponseException.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,34 @@ | ||
/* | ||
* This file is part of MinecraftAuth - https://github.com/RaphiMC/MinecraftAuth | ||
* Copyright (C) 2023 RK_01/RaphiMC and contributors | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package net.raphimc.minecraftauth.responsehandler.exception; | ||
|
||
import lombok.Getter; | ||
import org.apache.http.client.HttpResponseException; | ||
|
||
@Getter | ||
public class MsaResponseException extends HttpResponseException { | ||
|
||
private final String error; | ||
|
||
public MsaResponseException(final int statusCode, final String error, final String reasonPhrase) { | ||
super(statusCode, reasonPhrase + ", msa error: " + error); | ||
|
||
this.error = error; | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
...in/java/net/raphimc/minecraftauth/responsehandler/exception/PlayFabResponseException.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,34 @@ | ||
/* | ||
* This file is part of MinecraftAuth - https://github.com/RaphiMC/MinecraftAuth | ||
* Copyright (C) 2023 RK_01/RaphiMC and contributors | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package net.raphimc.minecraftauth.responsehandler.exception; | ||
|
||
import lombok.Getter; | ||
import org.apache.http.client.HttpResponseException; | ||
|
||
@Getter | ||
public class PlayFabResponseException extends HttpResponseException { | ||
|
||
private final String error; | ||
|
||
public PlayFabResponseException(final int statusCode, final String error, final String reasonPhrase) { | ||
super(statusCode, reasonPhrase + ", playfab error: " + error); | ||
|
||
this.error = error; | ||
} | ||
|
||
} |
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