Skip to content

Commit

Permalink
Added Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianFun123 committed Jun 3, 2021
1 parent 31832b6 commit 37bebc9
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
54 changes: 54 additions & 0 deletions README.md
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());
}

}
}
```
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>de.interaapps.accounts.apiclient</groupId>
<artifactId>accounts-api-client</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.0</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ public AuthorizationURLBuilder addScopes(String ...scope){
return this;
}

public AuthorizationURLBuilder setRedirectUrl(String redirectUrl) {
this.redirectUrl = redirectUrl;
return this;
}
public AuthorizationURLBuilder setState(String state) {
this.state = state;
return this;
}
public List<String> getScopes() {
return scopes;
}
Expand Down

0 comments on commit 37bebc9

Please sign in to comment.