Skip to content

Commit c0cf8e9

Browse files
#70 examples for Bearer Authentication
1 parent d51f8a1 commit c0cf8e9

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

examples/src/main/java/com/softlayer/api/example/Example.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ public void start(String[] args) throws Exception {
1717
baseUrl += '/';
1818
}
1919

20-
run(new RestApiClient(baseUrl).withCredentials(args[0], args[1]));
20+
RestApiClient client;
21+
// mvn -e -q compile exec:java -Dexec.args="QuickTest Bearer eyJraWQ.....
22+
if (args[0].trim().equals("Bearer")) {
23+
client = new RestApiClient(baseUrl).withBearerToken(args[1]);
24+
} else {
25+
client = new RestApiClient(baseUrl).withCredentials(args[0], args[1]);
26+
}
27+
run(client);
2128
}
2229

2330
/** Run the example with the given client */
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.softlayer.api.example;
2+
3+
import com.softlayer.api.ApiClient;
4+
import com.softlayer.api.RestApiClient;
5+
import com.softlayer.api.service.Account;
6+
7+
8+
/** A quick example for testing if authentication works.
9+
10+
cd softlayer-java/examples
11+
mvn -e -q compile exec:java -Dexec.args="QuickTest Bearer eyJraWQ.....
12+
*/
13+
public class QuickTest extends Example {
14+
15+
@Override
16+
public void run(ApiClient client) throws Exception {
17+
client.withLoggingEnabled();
18+
System.out.format("Authorization: %s\n", client.getCredentials());
19+
Account.Service service = Account.service(client);
20+
21+
Account account = service.getObject();
22+
System.out.format("Account Name: %s\n", account.getCompanyName());
23+
}
24+
25+
public static void main(String[] args) throws Exception {
26+
new QuickTest().start(args);
27+
}
28+
}

0 commit comments

Comments
 (0)