Skip to content

Commit

Permalink
Merge pull request #73 from ibm-cloud-security/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
vitalymibm committed Mar 7, 2017
2 parents 453d11b + 87abfc6 commit ce63324
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions BluemixAppIDTests/ConfigTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public class ConfigTests: XCTestCase {
AppID.sharedInstance = AppID()
// no region and tenant
let appid = AppID.sharedInstance
XCTAssertEqual("https://mobileclientaccess", Config.getServerUrl(appId: appid))
XCTAssertEqual("https://appid-oauth", Config.getServerUrl(appId: appid))

// with region and tenant
appid.initialize(tenantId: "sometenant", bluemixRegion: ".region")
XCTAssertEqual("https://mobileclientaccess.region/oauth/v3/sometenant", Config.getServerUrl(appId: appid))
XCTAssertEqual("https://appid-oauth.region/oauth/v3/sometenant", Config.getServerUrl(appId: appid))

// with overrideserverhost
AppID.overrideServerHost = "somehost/"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ AppID.sharedInstance.loginWidget?.launch(delegate: delegate())
BMSClient.sharedInstance.initialize(bluemixRegion: AppID.<region>)
BMSClient.sharedInstance.authorizationManager = AppIDAuthorizationManager(appid:AppID.sharedInstance)
var request:Request = Request(url: "<your protected resource url>")
r.send(completionHandler: {(response:Response?, error:Error?) in
request.send(completionHandler: {(response:Response?, error:Error?) in
//code handling the response here
})
```
Expand Down
2 changes: 1 addition & 1 deletion Source/BluemixAppID/internal/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Foundation
import BMSCore

internal class Config {
private static var serverUrlPrefix = "https://mobileclientaccess"
private static var serverUrlPrefix = "https://appid-oauth"
internal static let logger = Logger.logger(name: AppIDConstants.ConfigLoggerName)

internal static func getServerUrl(appId:AppID) -> String {
Expand Down
1 change: 1 addition & 0 deletions Source/BluemixAppID/internal/RegistrationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ internal class RegistrationManager {


internal func sendRequest(request:Request, registrationParamsAsData:Data?, internalCallBack: @escaping BMSCompletionHandler) {
request.urlSession.isBMSAuthorizationRequest = true
request.send(requestBody: registrationParamsAsData, completionHandler: internalCallBack)
}

Expand Down
19 changes: 11 additions & 8 deletions Source/BluemixAppID/internal/TokenManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal class TokenManager {
self.appid = oAuthManager.appId
self.registrationManager = oAuthManager.registrationManager!
}


public func obtainTokens(code:String, authorizationDelegate:AuthorizationDelegate) {
TokenManager.logger.debug(message: "obtainTokens")
Expand All @@ -33,14 +33,14 @@ internal class TokenManager {
guard let clientId = self.registrationManager.getRegistrationDataString(name: AppIDConstants.client_id_String), let redirectUri = self.registrationManager.getRegistrationDataString(arrayName: AppIDConstants.JSON_REDIRECT_URIS_KEY, arrayIndex: 0) else {
TokenManager.logger.error(message: "Client not registered")
authorizationDelegate.onAuthorizationFailure(error: AuthorizationError.authorizationFailure("Client not registered"))
return
return
}

var headers:[String:String] = [:]

do {
headers = [AppIDConstants.AUTHORIZATION_HEADER : try createAuthenticationHeader(clientId: clientId),
Request.contentType : "application/x-www-form-urlencoded"]
headers = [AppIDConstants.AUTHORIZATION_HEADER : try createAuthenticationHeader(clientId: clientId),
Request.contentType : "application/x-www-form-urlencoded"]
} catch (_) {
TokenManager.logger.error(message: "Failed to create authentication header")
authorizationDelegate.onAuthorizationFailure(error: AuthorizationError.authorizationFailure("Failed to create authentication header"))
Expand Down Expand Up @@ -81,6 +81,9 @@ internal class TokenManager {
}

internal func sendRequest(request:Request, body:Data?, internalCallBack: @escaping BMSCompletionHandler) {

request.urlSession.isBMSAuthorizationRequest = true

request.send(requestBody: body, completionHandler: internalCallBack)
}

Expand All @@ -94,8 +97,8 @@ internal class TokenManager {
return
}
do {
var responseJson = try Utils.parseJsonStringtoDictionary(responseText)

var responseJson = try Utils.parseJsonStringtoDictionary(responseText)
guard let accessTokenString = (responseJson["access_token"] as? String), let idTokenString = (responseJson["id_token"] as? String) else {
TokenManager.logger.error(message: "Failed to parse server response - no access or identity token")
authorizationDelegate.onAuthorizationFailure(error: AuthorizationError.authorizationFailure("Failed to parse server response - no access or identity token"))
Expand All @@ -114,7 +117,7 @@ internal class TokenManager {
authorizationDelegate.onAuthorizationFailure(error: AuthorizationError.authorizationFailure("Failed to parse server response - failed to parse json"))
return
}


}

Expand All @@ -127,7 +130,7 @@ internal class TokenManager {
self.latestAccessToken = nil
self.latestIdentityToken = nil
}




Expand Down

0 comments on commit ce63324

Please sign in to comment.