-
Notifications
You must be signed in to change notification settings - Fork 0
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
31832b6
commit 37bebc9
Showing
3 changed files
with
63 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Accounts Java Client | ||
|
||
## Normal usage | ||
```java | ||
import de.interaapps.accounts.apiclient.AccountsClient; | ||
|
||
class Example { | ||
public static void main(String[] args) { | ||
AccountsClient accountsClient = new AccountsClient("API-CLIENT"); | ||
System.out.println("Users Username: "+accountsClient.getProfile().getName()); | ||
|
||
// Example fetch for accepting all contacts | ||
accountsClient.getContactRequests().forEach(contactRequest -> { | ||
System.out.println("Username: "+contactRequest.getName()); | ||
contactRequest.accept(); | ||
}); | ||
} | ||
} | ||
``` | ||
|
||
## OAuth2 usage | ||
|
||
```java | ||
import de.interaapps.accounts.apiclient.AccountsClient; | ||
import de.interaapps.accounts.apiclient.oauth2.OAuth2Client; | ||
import de.interaapps.accounts.apiclient.responses.oauth2.OAuth2TokenExchangeResponse; | ||
|
||
class OAuth2Example { | ||
public static void main(String[] args) { | ||
OAuth2Client oAuth2Client = new OAuth2Client("CLIENT_ID", "CLIENT_SECRET"); | ||
|
||
// Send user to this url | ||
String url = oAuth2Client.createAuthorizationURL() | ||
.addScopes("user.description:read") | ||
.setRedirectUrl("https://myapp/authentication/interaapps") | ||
.build(); | ||
|
||
// When the user comes back, get the code query parameter and: | ||
|
||
// You may check the scopes before using it. | ||
if (oAuth2Client.checkScopes(scopes)) { | ||
|
||
OAuth2TokenExchangeResponse response = oAuth2Client.exchangeToken(code); | ||
|
||
System.out.println("Access-Token: "+response.getAccessToken()); | ||
// You can use the refresh token by just using exchangeToken(refreshtoken) | ||
System.out.println("Refresh-Token: "+response.getRefreshToken()); | ||
|
||
System.out.println("Users Name: "+response.getAccountsClient().getProfile().getName()); | ||
} | ||
|
||
} | ||
} | ||
``` |
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