             }
         }
     }
-    
-    /**
-     Request to refresh an access token.
-     
-     :param: completionHandler A block object to be executed when the request operation finishes.
-     */
+
+    /**
+    Request to refresh an access token.
+
+    :param: completionHandler A block object to be executed when the request operation finishes.
+    */
     public func refreshAccessToken(completionHandler: (AnyObject?, NSError?) -> Void) {
         if let unwrappedRefreshToken = self.oauth2Session.refreshToken {
             var paramDict: [String: String] = ["refresh_token": unwrappedRefreshToken, "client_id": config.clientId, "grant_type": "refresh_token"]
             if (config.clientSecret != nil) {
                 paramDict["client_secret"] = config.clientSecret!
             }
-            
+
             http.POST(config.refreshTokenEndpoint!, parameters: paramDict, completionHandler: { (response, error) in
                 if (error != nil) {
-                    if (error?.code == 400 || error?.code == 401 || error?.code == 403 || error?.code == 404) {
-                        self.revokeLocalAccess()
-                    }
-                    
                     completionHandler(nil, error)
                     return
                 }
-                
+
                 if let unwrappedResponse = response as? [String: AnyObject] {
                     let accessToken: String = unwrappedResponse["access_token"] as! String
                     let expiration = unwrappedResponse["expires_in"] as! NSNumber
                     let exp: String = expiration.stringValue
                     
                     self.oauth2Session.saveAccessToken(accessToken, refreshToken: unwrappedRefreshToken, accessTokenExpiration: exp, refreshTokenExpiration: nil)
-                    
+
                     completionHandler(unwrappedResponse["access_token"], nil);
                 }
             })
         }
     }
-    
-    /**
-     Exchange an authorization code for an access token.
-     
-     :param: code the 'authorization' code to exchange for an access token.
-     :param: completionHandler A block object to be executed when the request operation finishes.
-     */
+
+    /**
+    Exchange an authorization code for an access token.
+
+    :param: code the 'authorization' code to exchange for an access token.
+    :param: completionHandler A block object to be executed when the request operation finishes.
+    */
     public func exchangeAuthorizationCodeForAccessToken(code: String, completionHandler: (AnyObject?, NSError?) -> Void) {
         var paramDict: [String: String] = ["code": code, "client_id": config.clientId, "redirect_uri": config.redirectURL, "grant_type":"authorization_code"]
         

}

/**
 Parent class of any OAuth2 module implementing generic OAuth2 authorization flow.
 */
public class OAuth2Module: AuthzModule {
    let config: Config
    var http: Http
    
    var oauth2Session: OAuth2Session
    var applicationLaunchNotificationObserver: NSObjectProtocol?
    var applicationDidBecomeActiveNotificationObserver: NSObjectProtocol?
    var state: AuthorizationState
    var webView: OAuth2WebViewController?

    public static let revokeNotification = "kRevokeNotification"
    
    /**
     Initialize an OAuth2 module.
     
     :param: config the configuration object that setups the module.
     :param: session the session that that module will be bound to.
     :param: requestSerializer the actual request serializer to use when performing requests.
     :param: responseSerializer the actual response serializer to use upon receiving a response.
     
     :returns: the newly initialized OAuth2Module.
     */
    public required init(config: Config, session: OAuth2Session? = nil, requestSerializer: RequestSerializer = HttpRequestSerializer(), responseSerializer: ResponseSerializer = JsonResponseSerializer()) {
        if (config.accountId == nil) {
            config.accountId = "ACCOUNT_FOR_CLIENTID_\(config.clientId)"

            return ["Authorization":"Bearer \(self.oauth2Session.accessToken!)"]
        }
    }

    /**
    Returns a boolean indicating whether authorization has been granted.

    :returns: true if authorized, false otherwise.
    */
    public func isAuthorized() -> Bool {
        return self.oauth2Session.accessToken != nil && self.oauth2Session.tokenIsNotExpired()
    }

    // MARK: Internal Methods

    func extractCode(notification: NSNotification, completionHandler: (AnyObject?, NSError?) -> Void) {
        let url: NSURL? = (notification.userInfo as! [String: AnyObject])[UIApplicationLaunchOptionsURLKey] as? NSURL

        // extract the code from the URL
        let code = self.parametersFromQueryString(url?.query)["code"]
        // if exists perform the exchange
