             }
         }
     }
-    
-    /**
-     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"]
         

            }
            
        }
        
    }
    
    /**
     Gateway to login with client credentials
     
     :param: completionHandler A block object to be executed when the request operation finishes.
     */
    public func loginClientCredentials(completionHandler: (AnyObject?, OpenIDClaim?, NSError?) -> Void) {
        
        let paramDict: [String: String] = ["client_id": config.clientId, "client_secret": config.clientSecret!, "scope": config.scope, "grant_type": "client_credentials"]
        
        http.POST(config.accessTokenEndpoint, parameters: paramDict, completionHandler: { (response, error) in
            if (error != nil) {
                completionHandler(nil, nil, error)
                return
            }
            
            if let unwrappedResponse = response as? [String: AnyObject] {
                let accessToken: String = unwrappedResponse["access_token"] as! String
                let refreshToken: String? = unwrappedResponse["refresh_token"] as? String
                let expiration = unwrappedResponse["expires_in"] as? NSNumber
                let exp: String? = expiration?.stringValue
                // expiration for refresh token is used in Keycloak
                let expirationRefresh = unwrappedResponse["refresh_expires_in"] as? NSNumber
                let expRefresh = expirationRefresh?.stringValue
                
                // in Keycloak refresh token get refreshed every time you use them
                self.oauth2Session.saveAccessToken(accessToken, refreshToken: refreshToken, accessTokenExpiration: exp, refreshTokenExpiration: expRefresh)
                completionHandler(accessToken,nil, nil);
            }
        })
    }
    
    /**
     Request to revoke access.
     
     :param: completionHandler A block object to be executed when the request operation finishes.
     */
    public func revokeAccess(completionHandler: (AnyObject?, NSError?) -> Void) {
        // return if not yet initialized
        if (self.oauth2Session.accessToken == nil) {
            return;
        }
        let paramDict:[String:String] = ["token":self.oauth2Session.accessToken!]
        
        http.POST(config.revokeTokenEndpoint!, parameters: paramDict, completionHandler: { (response, error) in
            if (error != nil) {
                completionHandler(nil, error)
                return
            }
            
            self.oauth2Session.clearTokens()
            completionHandler(response, nil)
        })
    }
    
    public func revokeLocalAccess() -> Void {
        self.oauth2Session.clearTokens()
        let notification = NSNotification(name: OAuth2Module.revokeNotification, object:nil, userInfo:nil)
        NSNotificationCenter.defaultCenter().postNotification(notification)
        
    }
    
    public func revokeLocalAccessToken() {
        self.oauth2Session.clearAccessTokens()
    }
    
    /**
     Return any authorization fields.
     
     
     
     :returns:  a dictionary filled with the authorization fields.
     */
    public func authorizationFields() -> [String: String]? {
        if (self.oauth2Session.accessToken == nil) {
            return nil

        } else {
            self.oauth2Session = session!
        }

        self.config = config
        if config.isWebView {
            self.webView = OAuth2WebViewController()
