Skip to content

Commit 134b173

Browse files
committed
Added Constructors to Allow Import of External Tokens
1 parent be422d0 commit 134b173

File tree

5 files changed

+50
-1
lines changed

5 files changed

+50
-1
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ hs_err_pid*
4545
.idea/**/workspace.xml
4646
.idea/**/tasks.xml
4747
.idea/dictionaries
48+
.idea/
4849

4950
# Sensitive or high-churn files:
5051
.idea/**/dataSources/
@@ -124,3 +125,6 @@ $RECYCLE.BIN/
124125

125126
# .nfs files are created when an open file is removed but is still being accessed
126127
.nfs*
128+
129+
# lombok config
130+
lombok.config

gradle/wrapper/gradle-wrapper.jar

-53.1 KB
Binary file not shown.

src/main/java/com/bhyoo/onedrive/client/Client.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.bhyoo.onedrive.client.auth.AbstractAuthHelper;
44
import com.bhyoo.onedrive.client.auth.AuthHelper;
5+
import com.bhyoo.onedrive.client.auth.AuthenticationInfo;
56
import com.bhyoo.onedrive.container.AsyncJobMonitor;
67
import com.bhyoo.onedrive.container.items.*;
78
import com.bhyoo.onedrive.container.items.pointer.BasePointer;
@@ -25,6 +26,7 @@
2526
import java.nio.file.Files;
2627
import java.nio.file.Path;
2728
import java.nio.file.Paths;
29+
import java.util.Arrays;
2830

2931
import static com.bhyoo.onedrive.container.items.pointer.Operator.*;
3032
import static io.netty.handler.codec.http.HttpMethod.GET;
@@ -96,6 +98,30 @@ public Client(@NotNull String clientId, @NotNull String[] scope, @NotNull String
9698
}
9799

98100

101+
/**
102+
* Constructor used when authorization is handled by an external system. In this case, the accessToken,
103+
* refreshToken and expiresIn values have been obtained elsewhere.
104+
* @param clientId The OAuth clientID
105+
* @param scope A {@link String[]} of scopes
106+
* @param redirectURL The OAuth redirect URL
107+
* @param clientSecret The OAuth clientSecret token
108+
* @param accessToken The OAuth accessToken
109+
* @param refreshToken The OAuth refreshToken
110+
* @param tokenType The OAuth tokenType
111+
* @param expiresIn The OAuth expiresIn value
112+
*/
113+
public Client(@NotNull String clientId,
114+
@NotNull String[] scope,
115+
@NotNull String redirectURL,
116+
@NotNull String clientSecret,
117+
@NotNull String accessToken,
118+
@NotNull String refreshToken,
119+
String tokenType,
120+
long expiresIn) {
121+
requestTool = new RequestTool(this);
122+
AuthenticationInfo authInfo = new AuthenticationInfo(tokenType, expiresIn, accessToken, refreshToken, Arrays.toString(scope));
123+
authHelper = new AuthHelper(scope, clientId, clientSecret, redirectURL, requestTool, authInfo);
124+
}
99125

100126

101127
/*

src/main/java/com/bhyoo/onedrive/client/auth/AuthHelper.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,25 @@ public AuthHelper(@NotNull String[] scopes, @NotNull String clientId, @NotNull S
4646
this.requestTool = requestTool;
4747
}
4848

49+
/**
50+
* Creates an AuthHelper object when the initial access and refresh tokens are obtained programmatically.
51+
* @param scopes A list of scopes
52+
* @param clientId The OAuth 2.0 clientID token
53+
* @param clientSecret The OAuth 2.0 client secret token
54+
* @param redirectURL The OAuth 2.0 redirect URL
55+
* @param requestTool The {@link RequestTool} for making HTTP requests
56+
* @param authInfo The {@link AuthenticationInfo} containing the access and refresh tokens.
57+
*/
58+
public AuthHelper(@NotNull String[] scopes, @NotNull String clientId, @NotNull String clientSecret,
59+
@NotNull String redirectURL, @NotNull RequestTool requestTool, @NotNull AuthenticationInfo authInfo) {
60+
this.scopes = scopes;
61+
this.clientId = clientId;
62+
this.clientSecret = clientSecret;
63+
this.redirectURL = redirectURL;
64+
this.requestTool = requestTool;
65+
this.authInfo = authInfo;
66+
}
67+
4968

5069
@Override public boolean isLogin() {
5170
return authCode != null && authInfo != null;

src/main/java/com/bhyoo/onedrive/client/auth/AuthenticationInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class AuthenticationInfo {
2121
@Getter @JsonProperty("refresh_token") protected @NotNull String refreshToken;
2222
@Getter protected String scope;
2323

24-
protected AuthenticationInfo(@NotNull String tokenType, long expiresIn, @NotNull String accessToken,
24+
public AuthenticationInfo(@NotNull String tokenType, long expiresIn, @NotNull String accessToken,
2525
@NotNull String refreshToken, @NotNull String scope) {
2626
this.tokenType = tokenType;
2727
this.expiresIn = expiresIn;

0 commit comments

Comments
 (0)