Skip to content
This repository was archived by the owner on Aug 23, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/main/java/mastodon/api/LoginProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,10 @@ public String getLoginURL() {
return url.build();
}

public MastodonSession authorize(String code) throws IOException {
public TokenResponse authorize(String code) throws IOException {
AuthorizationCodeTokenRequest request = flow.newTokenRequest(code);
if (redirectUri != null)
request.setRedirectUri(redirectUri);

TokenResponse response = request.execute();
Credential credential = new Credential(flow.getMethod()).setFromTokenResponse(response);

return new MastodonSession(app, credential);
return request.execute();
}
}
9 changes: 9 additions & 0 deletions src/main/java/mastodon/api/MastodonSession.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package mastodon.api;

import com.google.api.client.auth.oauth2.AuthorizationCodeFlow;
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.auth.oauth2.TokenResponse;
import com.google.api.client.http.*;
import com.google.gson.reflect.TypeToken;
import mastodon.api.internal.FormDataContent;
import mastodon.api.internal.RequestsHelper;
import mastodon.api.objects.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
Expand Down Expand Up @@ -35,6 +38,12 @@ public class MastodonSession {
this.credential = credential;
}

public static MastodonSession getSession(MastodonApp app, TokenResponse tokenResponse, Scope... scopes) {
AuthorizationCodeFlow flow = RequestsHelper.createFlow(app, scopes);
Credential credential = new Credential(flow.getMethod()).setFromTokenResponse(tokenResponse);
return new MastodonSession(app, credential);
}

public Raw raw() {
return raw;
}
Expand Down