ibm-cloud-security / appid-serversdk-swift Goto Github PK
View Code? Open in Web Editor NEWSwift server SDK for the IBM Cloud App ID service
License: Apache License 2.0
Swift server SDK for the IBM Cloud App ID service
License: Apache License 2.0
This library is (we think) the last IBM Swift package to depend on SwiftyJSON.
SwiftyJSON has been obsolete since Swift 4 in 2017, when Codable and JSONEncoder were introduced.
Unfortunately this package exposes SwiftyJSON types in its public API, so removing SwiftyJSON will be SemVer Major.
SwiftyJSON currently does not currently support Swift 5.1 so unless this is fixed this package cannot support Swift 5.1.
Per https://github.ibm.com/security-services/appid-project-management/issues/541
Adding API strategy to swift SDK with token validation (--> signature verification)
AppID currently uses the ibm-bluemix-mobile-services/bluemix-simple-logger-swift package which needs updating for Swift 5 (actually, it still needs updating for Swift 4).
AppID could instead use IBM-Swift/LoggerAPI, which supports Swift 4 and 5 already. Doing so would also make the logging behaviour consistent with Kitura, give the user control over what output is logged, and allow them to use their own logger implementation.
I just cloned and compiled the project and ran swift test
but there are 4 failures due to XCTAssertEquals failing to compare to two values.
From the output its a mismatch due to the redirect URI expecting "...http:%2F%2F..." but the test returns a %3A instead of a : so it would return "...http%3A%2F%2F..." which causes it to fail.
Running https://github.com/IBM-Swift/Kitura-Sample project using provided Dockerfiles and instructions I try to login using App ID.
I press the button and get redirected to my App ID login page, I fill in the email and password, and get redirected back to login fail url.
The output it the console is:
[DBG] [WebAppKituraCredentialsPlugin] WebAppKituraCredentialsPlugin :: handleAuthorization
[DBG] [WebAppKituraCredentialsPlugin] AUTHURL: ...
[DBG] [WebAppKituraCredentialsPlugin] Redirecting to : ...
[DBG] [WebAppKituraCredentialsPlugin] WebAppKituraCredentialsPlugin :: retrieveTokens
[DBG] [WebAppKituraCredentialsPlugin] WebAppKituraCredentialsPlugin :: Failed to obtain tokens. error message : Error HTTP Response:500
status code : 500
token body : Optional(149 bytes)
After digging down a bit trying to find the origin of the error I found a method inside WebAppKituraCredentialsPlugin
fileprivate func retrieveTokens(options: [String: Any],
grantCode: String,
onFailure: @escaping (HTTPStatusCode?, [String: String]?) -> Void,
request: RouterRequest,
onSuccess: @escaping (UserProfile) -> Void) {
logger.debug("WebAppKituraCredentialsPlugin :: retrieveTokens")
guard let clientId = config.clientId,
let secret = config.secret,
let serverUrl = config.serverUrl else {
onFailure(nil, nil)
return
}
let tokenEndpoint = serverUrl + Constants.Endpoints.token
let redirectUri = config.redirectUri
let authorization = clientId + ":" + secret
let restReq = RestRequest(method: .post, url: tokenEndpoint, containsSelfSignedCert: false)
restReq.headerParameters = ["Authorization": "basic " + Data(authorization.utf8).base64EncodedString()]
let params = [ "client_id": clientId,
"grant_type": "authorization_code",
"redirect_uri": redirectUri,
"code": grantCode ]
if let json = try? JSONSerialization.data(withJSONObject: params, options: []) {
restReq.messageBody = json
} else {
logger.debug("Failed to parse data into JSON.")
}
restReq.response { (tokenData, tokenResponse, tokenError) in
self.handleTokenResponse(httpCode: tokenResponse?.statusCode,
tokenData: tokenData,
tokenError: tokenError,
originalRequest: request,
onFailure: onFailure,
onSuccess: onSuccess)
}
}
Everything look fine up until:
restReq.response { (tokenData, tokenResponse, tokenError) in
...
}
which returns empty tokenData, and an error:
po tokenError!.localizedDescription
"The operation couldn’t be completed. (SwiftyRequest.RestError error 0.)"
So it looks like WebAppKituraCredentials request to App ID server generates a 500 error.
Kitura-Credentials has removed its dependency on SwiftyJSON and without an explicit package declaration, there is no longer SwiftyJSON package access.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.