diff --git a/Source/ARTAuth.m b/Source/ARTAuth.m index b19d2aa7c..f49485f53 100644 --- a/Source/ARTAuth.m +++ b/Source/ARTAuth.m @@ -334,7 +334,6 @@ - (void)authorise:(ARTTokenParams *)tokenParams options:(ARTAuthOptions *)authOp } - (void)authorize:(ARTTokenParams *)tokenParams options:(ARTAuthOptions *)authOptions callback:(void (^)(ARTTokenDetails *, NSError *))callback { - ARTAuthOptions *replacedOptions = [authOptions copy] ? : [self.options copy]; [self storeOptions:replacedOptions]; @@ -351,6 +350,7 @@ - (void)authorize:(ARTTokenParams *)tokenParams options:(ARTAuthOptions *)authOp } } else { _tokenDetails = tokenDetails; + _method = ARTAuthMethodToken; [self.logger verbose:@"RS:%p ARTAuth: token request succeeded: %@", _rest, tokenDetails]; if (callback) { callback(self.tokenDetails, nil); diff --git a/Spec/Auth.swift b/Spec/Auth.swift index 7a9dbc7f6..90c1d3a9d 100644 --- a/Spec/Auth.swift +++ b/Spec/Auth.swift @@ -1728,6 +1728,56 @@ class Auth : QuickSpec { } } + // RSA10a + it("should create a new token if one already exist and ensure Token Auth is used for all future requests") { + let options = AblyTests.commonAppSetup() + let testToken = getTestToken() + options.token = testToken + let rest = ARTRest(options: options) + + expect(rest.auth.tokenDetails?.token).toNot(beNil()) + waitUntil(timeout: testTimeout) { done in + rest.auth.authorize(nil, options: nil, callback: { tokenDetails, error in + guard let tokenDetails = tokenDetails else { + XCTFail("TokenDetails is nil"); done(); return + } + expect(tokenDetails.token).toNot(equal(testToken)) + expect(rest.auth.method).to(equal(ARTAuthMethod.Token)) + + publishTestMessage(rest, completion: { error in + expect(error).to(beNil()) + expect(rest.auth.method).to(equal(ARTAuthMethod.Token)) + expect(rest.auth.tokenDetails?.token).to(equal(tokenDetails.token)) + done() + }) + }) + } + } + + // RSA10a + it("should create a token immediately and ensures Token Auth is used for all future requests") { + let options = AblyTests.commonAppSetup() + let rest = ARTRest(options: options) + + expect(rest.auth.tokenDetails?.token).to(beNil()) + waitUntil(timeout: testTimeout) { done in + rest.auth.authorize(nil, options: nil, callback: { tokenDetails, error in + guard let tokenDetails = tokenDetails else { + XCTFail("TokenDetails is nil"); done(); return + } + expect(tokenDetails.token).toNot(beNil()) + expect(rest.auth.method).to(equal(ARTAuthMethod.Token)) + + publishTestMessage(rest, completion: { error in + expect(error).to(beNil()) + expect(rest.auth.method).to(equal(ARTAuthMethod.Token)) + expect(rest.auth.tokenDetails?.token).to(equal(tokenDetails.token)) + done() + }) + }) + } + } + // RSA10b it("should supports all TokenParams and AuthOptions") { let rest = ARTRest(options: AblyTests.commonAppSetup())