-
Notifications
You must be signed in to change notification settings - Fork 527
Add IAM support #929
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
Merged
Add IAM support #929
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
9b27f08
feat(core): Add initial changes for IAM support
lpatino10 da47bdc
feat(assistant): Add testing lines for IAM support
lpatino10 3a841e4
refactor(core): Use proper form to make IAM API call and switch to ha…
lpatino10 a671643
style(core): Add comments, style changes for clarity
lpatino10 5f8cf38
refactor(core): Return just the access token string from requestToken…
lpatino10 8aaae7c
refactor(core): Use constructor instead of builder for IamToken
lpatino10 d39dbdf
refactor(core): Change options model for IAM and keep user-managed to…
lpatino10 1bc675e
refactor(core): Don't accept refresh token when instantiating service…
lpatino10 9b49c96
refactor(core): Replace IAM ServiceCall implementation with a single …
lpatino10 9b621ad
feat(core): Add method to set user-managed access token outside of co…
lpatino10 3dffb61
refactor(core): Tweak manner of setting IAM credentials from user POV…
lpatino10 0c86ade
feat(core): Get IAM API key from VCAP_SERVICES if available
lpatino10 9e60eeb
test(core): Add test for getting IAM API key from VCAP_SERVICES
lpatino10 06f61dd
test(core): Add remaining IAM unit tests
lpatino10 170b94e
refactor(assistant): Remove changes for testing specifically in Assis…
lpatino10 c0ba4aa
Merge branch 'develop' into iam-support
lpatino10 722ca5c
feat(service-constructors): Add constructors for IAM authentication
lpatino10 235f273
refactor(services): Fix merge conflicts
lpatino10 3341a8d
fix(conversation): Add back method that accidentally got deleted
lpatino10 34577e1
feat(core): Add check for expired refresh token
lpatino10 33ab80b
style(nlu): Fix checkstyle complaint
lpatino10 25c7a7d
fix(core): Fix null check in IAM logic
lpatino10 f61a9a3
feat(core): Pull IAM URL from VCAP_SERVICES
lpatino10 772ae6a
style(core): Use string constants for IAM logic
lpatino10 66773bd
refactor(core): Only expose getToken method in IamTokenManager
lpatino10 6f80223
docs(main README): Add documentation about using IAM
lpatino10 31c42de
docs(main README): Address review comments
lpatino10 f44c5af
refactor(core): Allow tokenManager creation if IAM URL is not in VCAP…
lpatino10 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,6 +81,7 @@ | |
| import com.ibm.watson.developer_cloud.http.RequestBuilder; | ||
| import com.ibm.watson.developer_cloud.http.ServiceCall; | ||
| import com.ibm.watson.developer_cloud.service.WatsonService; | ||
| import com.ibm.watson.developer_cloud.service.security.IamOptions; | ||
| import com.ibm.watson.developer_cloud.util.GsonSingleton; | ||
| import com.ibm.watson.developer_cloud.util.ResponseConverterUtils; | ||
| import com.ibm.watson.developer_cloud.util.Validator; | ||
|
|
@@ -130,8 +131,20 @@ public Assistant(String versionDate, String username, String password) { | |
| } | ||
|
|
||
| /** | ||
| * Get response to user input. | ||
| * Instantiates a new `Assistant` with IAM. Note that if the access token is specified in the iamOptions, | ||
| * you accept responsibility for managing the access token yourself. You must set a new access token before this one | ||
| * expires. Failing to do so will result in authentication errors after this token expires. | ||
| * | ||
| * @param versionDate The version date (yyyy-MM-dd) of the REST API to use. Specifying this value will keep your API | ||
| * calls from failing when the service introduces breaking changes. | ||
| * @param iamOptions the options for authenticating through IAM | ||
| */ | ||
| public Assistant(String versionDate, IamOptions iamOptions) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They just need to provide |
||
| this(versionDate); | ||
| setIamCredentials(iamOptions); | ||
| } | ||
|
|
||
| /** | ||
| * Get a response to a user's input. There is no rate limit for this operation. | ||
| * | ||
| * @param messageOptions the {@link MessageOptions} containing the options for the call | ||
|
|
||
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
65 changes: 65 additions & 0 deletions
65
core/src/main/java/com/ibm/watson/developer_cloud/service/security/IamOptions.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,65 @@ | ||
| /* | ||
| * Copyright 2018 IBM Corp. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
| * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations under the License. | ||
| */ | ||
| package com.ibm.watson.developer_cloud.service.security; | ||
|
|
||
| /** | ||
| * Options for authenticating using IAM. | ||
| */ | ||
| public class IamOptions { | ||
| private String apiKey; | ||
| private String accessToken; | ||
| private String url; | ||
|
|
||
| public String getApiKey() { | ||
| return apiKey; | ||
| } | ||
|
|
||
| public String getAccessToken() { | ||
| return accessToken; | ||
| } | ||
|
|
||
| public String getUrl() { | ||
| return url; | ||
| } | ||
|
|
||
| public static class Builder { | ||
| private String apiKey; | ||
| private String accessToken; | ||
| private String url; | ||
|
|
||
| public IamOptions build() { | ||
| return new IamOptions(this); | ||
| } | ||
|
|
||
| public Builder apiKey(String apiKey) { | ||
| this.apiKey = apiKey; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder accessToken(String accessToken) { | ||
| this.accessToken = accessToken; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder url(String url) { | ||
| this.url = url; | ||
| return this; | ||
| } | ||
| } | ||
|
|
||
| private IamOptions(Builder builder) { | ||
| this.apiKey = builder.apiKey; | ||
| this.accessToken = builder.accessToken; | ||
| this.url = builder.url; | ||
| } | ||
| } |
51 changes: 51 additions & 0 deletions
51
core/src/main/java/com/ibm/watson/developer_cloud/service/security/IamToken.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,51 @@ | ||
| /* | ||
| * Copyright 2018 IBM Corp. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
| * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations under the License. | ||
| */ | ||
| package com.ibm.watson.developer_cloud.service.security; | ||
|
|
||
| import com.google.gson.annotations.SerializedName; | ||
| import com.ibm.watson.developer_cloud.service.model.ObjectModel; | ||
|
|
||
| /** | ||
| * Represents response from IAM API. | ||
| */ | ||
| public class IamToken implements ObjectModel { | ||
| @SerializedName("access_token") | ||
| private String accessToken; | ||
| @SerializedName("refresh_token") | ||
| private String refreshToken; | ||
| @SerializedName("token_type") | ||
| private String tokenType; | ||
| @SerializedName("expires_in") | ||
| private Long expiresIn; | ||
| private Long expiration; | ||
|
|
||
| public String getAccessToken() { | ||
| return accessToken; | ||
| } | ||
|
|
||
| public String getRefreshToken() { | ||
| return refreshToken; | ||
| } | ||
|
|
||
| public String getTokenType() { | ||
| return tokenType; | ||
| } | ||
|
|
||
| public Long getExpiresIn() { | ||
| return expiresIn; | ||
| } | ||
|
|
||
| public Long getExpiration() { | ||
| return expiration; | ||
| } | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that you point this out to the user!