-
Notifications
You must be signed in to change notification settings - Fork 25
Bearer token auth support #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
allmightyspiff
merged 5 commits into
softlayer:master
from
allmightyspiff:bearerTokenAuth
Jan 14, 2021
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c0cf8e9
#70 examples for Bearer Authentication
allmightyspiff 0cdfb8d
#70 support for Bearer HTTP authorization
allmightyspiff 194e716
#70 added code coverage tool to pom.xml, and a BuiltinHttpClientFacto…
allmightyspiff 80ed0e7
cleared up some documentation for BearerAuthorization
allmightyspiff 1e82fa3
fixed pull request feedback
allmightyspiff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
28 changes: 28 additions & 0 deletions
28
examples/src/main/java/com/softlayer/api/example/QuickTest.java
This file contains hidden or 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,28 @@ | ||
| package com.softlayer.api.example; | ||
|
|
||
| import com.softlayer.api.ApiClient; | ||
| import com.softlayer.api.RestApiClient; | ||
| import com.softlayer.api.service.Account; | ||
|
|
||
|
|
||
| /** A quick example for testing if authentication works. | ||
|
|
||
| cd softlayer-java/examples | ||
| mvn -e -q compile exec:java -Dexec.args="QuickTest Bearer eyJraWQ..... | ||
| */ | ||
| public class QuickTest extends Example { | ||
|
|
||
| @Override | ||
| public void run(ApiClient client) throws Exception { | ||
| client.withLoggingEnabled(); | ||
| System.out.format("Authorization: %s\n", client.getCredentials()); | ||
| Account.Service service = Account.service(client); | ||
|
|
||
| Account account = service.getObject(); | ||
| System.out.format("Account Name: %s\n", account.getCompanyName()); | ||
| } | ||
|
|
||
| public static void main(String[] args) throws Exception { | ||
| new QuickTest().start(args); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
24 changes: 24 additions & 0 deletions
24
src/main/java/com/softlayer/api/http/HttpBearerCredentials.java
This file contains hidden or 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,24 @@ | ||
| package com.softlayer.api.http; | ||
|
|
||
| /** HTTP Bearer authorization support for IBM IAM Tokens. | ||
| * | ||
| * @see <a href="https://cloud.ibm.com/apidocs/iam-identity-token-api">IAM Tokens</a> | ||
| * @see <a href="https://sldn.softlayer.com/article/authenticating-softlayer-api/">Authenticating SoftLayer API</a> | ||
| */ | ||
| public class HttpBearerCredentials implements HttpCredentials { | ||
|
|
||
| protected final String token; | ||
|
|
||
| public HttpBearerCredentials(String token) { | ||
| this.token = token; | ||
| } | ||
|
|
||
| /** | ||
| * Formats the token into a HTTP Authorization header. | ||
| * | ||
| * @return String | ||
| */ | ||
| public String getHeader() { | ||
| return "Bearer " + token; | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -2,4 +2,5 @@ | |
|
|
||
| /** Base interface for all accepted HTTP credentials */ | ||
| public interface HttpCredentials { | ||
| String getHeader(); | ||
| } | ||
This file contains hidden or 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
22 changes: 22 additions & 0 deletions
22
src/test/java/com/softlayer/api/http/HttpBearerCredentialsTest.java
This file contains hidden or 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,22 @@ | ||
| package com.softlayer.api.http; | ||
|
|
||
| import static org.junit.Assert.*; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| public class HttpBearerCredentialsTest { | ||
|
|
||
| public final String bearerToken = "qqqqwwwweeerrttyyuuiiooppasddfgfgjghjkjklZXxcvcvbvbnnbm"; | ||
| @Test | ||
| public void testConstructor() { | ||
| HttpBearerCredentials authCredentials = new HttpBearerCredentials(bearerToken); | ||
| assertEquals(bearerToken, authCredentials.token); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetHeader() { | ||
| HttpBearerCredentials authCredentials = new HttpBearerCredentials(bearerToken); | ||
| String header = "Bearer " + bearerToken; | ||
| assertEquals(header, authCredentials.getHeader()); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.