Skip to content

Commit f268c7f

Browse files
committed
Introducing improved OAuth
1 parent ed64df3 commit f268c7f

3 files changed

Lines changed: 22 additions & 15 deletions

File tree

README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
# JavaDestinyAPI
2-
<<<<<<< HEAD
32
This is a java wrapper for the API provided by bungie to control things on Bungie.net and inside the game Destiny 2. It handles all of the neccessary HTTP requests async and parses the Json response for you.
43

54
The API is far from complete, and currently only handles the basics of what you might need. You can get users and clans by their names or ids and get details about them. You can also control your clan such as kicking, banning and inviting players, as long as you have set up OAuth.
65

76
## Getting Started
8-
=======
97
This is a java wrapper for the API provided by bungie to control things on the Bungie.net platform.
108
The API is far from complete, and currently only handles the basics of what you might need. You can get users and clans by their names or ids and get details about them. You can also control your clan such as kicking, banning and inviting players, as long as you have set up OAuth.
119

@@ -14,7 +12,6 @@ This project is currently not a member of any maven repository, so you have to d
1412
- Download the most recently available jar from [releases](https://github.com/dec4234/JavaDestinyAPI/releases)
1513
- Create a folder called lib inside of your project folder (the one in such place as eclipse-workspace)
1614
- Place the jar into that folder then add this maven dependency inside of your pom.xml
17-
>>>>>>> 9ce3da3ce0026cdd15b6b7b3fa265a40f66db14c
1815
This project can be currently accesed through the jitpack repository, which allows any github repo to be used as a dependency
1916
```
2017
<repository>
@@ -36,11 +33,11 @@ Check out the [wiki](https://github.com/dec4234/JavaDestinyAPI/wiki/Getting-Star
3633

3734
## How's it made?
3835
There is both offical and unoffical documentation for the API available on [destinydevs.github.io](http://destinydevs.github.io/BungieNetPlatform/docs/Endpoints) and on the [offical bungie api documentation](https://bungie-net.github.io/).
39-
=======
36+
```
37+
<dependency>
4038
<version>1.0</version>
4139
<scope>system</scope>
4240
<systemPath>${basedir}/lib/JavaDestinyAPI.jar</systemPath>
4341
<version>master</version>
4442
</dependency>
45-
```
46-
>>>>>>> 9ce3da3ce0026cdd15b6b7b3fa265a40f66db14c
43+
```

src/main/java/material/DestinyAPI.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,12 @@ public static Clan getClan(String name) {
124124

125125
public static String getOauthCode() { return oauthCode; }
126126

127-
public static String getAccessToken() { return accessToken; }
127+
public static String getAccessToken() {
128+
return oam.getAccessToken();
129+
}
128130

129-
public static String getRefreshToken() { return refreshToken; }
131+
public static String getRefreshToken() {
132+
return oam.getRefreshToken();
133+
}
130134

131135
}

src/main/java/utils/HttpUtils.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
public class HttpUtils {
2929

3030
String apiKey = DestinyAPI.getApiKey();
31-
private static String bearerToken = FileUtils.getInfo("access_token");
31+
private static String bearerToken = DestinyAPI.getAccessToken();
3232

3333
/**
3434
* Send a GET url request to the url provided, returns a JsonObject of the response
@@ -61,7 +61,6 @@ public String urlRequestGETstring(String url) {
6161
.GET()
6262
.build();
6363
CompletableFuture<String> response = client.sendAsync(request, HttpResponse.BodyHandlers.ofString()).thenApplyAsync(HttpResponse::body);
64-
JsonElement parse = null;
6564
try {
6665
return response.get();
6766
} catch (InterruptedException | ExecutionException e) {
@@ -153,7 +152,7 @@ public String generateLineGraph() {
153152
public String setTokenViaRefresh() {
154153
String url = "https://www.bungie.net/Platform/App/OAuth/Token/";
155154

156-
String requestBody = "grant_type=refresh_token&refresh_token=" + FileUtils.getInfo("refresh_token");
155+
String requestBody = "grant_type=refresh_token&refresh_token=" + DestinyAPI.getRefreshToken();
157156

158157
HttpClient client = HttpClient.newHttpClient();
159158
HttpRequest request = HttpRequest.newBuilder()
@@ -172,12 +171,14 @@ public String setTokenViaRefresh() {
172171
}
173172
String at = parse.getAsJsonObject().get("access_token").getAsString();
174173
String rt = parse.getAsJsonObject().get("refresh_token").getAsString();
174+
/*
175175
FileUtils.setInfo("refresh_token", rt);
176176
FileUtils.setInfo("access_token", at);
177+
*/
177178
bearerToken = at;
178179
new DestinyAPI().setAccessToken(at).setRefreshToken(rt);
179180

180-
return parse.getAsJsonObject().get("access_token").getAsString();
181+
return at;
181182
}
182183

183184
public void setTokenViaAuth() {
@@ -202,23 +203,28 @@ public void setTokenViaAuth() {
202203
}
203204
String accessToken = parse.getAsJsonObject().get("access_token").getAsString();
204205
String refreshToken = parse.getAsJsonObject().get("refresh_token").getAsString();
206+
/*
205207
FileUtils.clear();
206208
FileUtils.setInfo("access_token", accessToken);
207209
FileUtils.setInfo("refresh_token", refreshToken);
208-
HttpUtils.bearerToken = FileUtils.getInfo("access_token");
210+
*/
209211

210212
new DestinyAPI().setAccessToken(accessToken).setRefreshToken(refreshToken);
213+
214+
HttpUtils.bearerToken = accessToken;
211215
}
212216

213-
public void checkFor401(String input) {
217+
public boolean checkFor401(String input) {
214218
if(input.contains("401 - Unauthorized")) {
215219
try {
216220
setTokenViaRefresh();
217221
throw new AccessTokenInvalidException("The access token used in this OAuth request was not accepted by the server \nI've already taken the liberty of getting a new access token for you :D");
218222
} catch (AccessTokenInvalidException e) {
219223
e.printStackTrace();
220-
System.exit(401);
224+
return true;
221225
}
222226
}
227+
228+
return false;
223229
}
224230
}

0 commit comments

Comments
 (0)