 
     public static func setup() {
         loadConfig()
-        if let p = profile, let a = account, let token = a.accessToken.accessToken {
-            CloudAPIClient.login(profile: p, token: token)
-            if isExpired {
-                refreshAccessToken(a)
-            }
-        } else {
-            profile = nil
-            clearAllAccount()
+        oauth = OAuth2Swift(
+            consumerKey:    clientId,
+            consumerSecret: clientSecret,
+            authorizeUrl:   shared.authUrl,
+            accessTokenUrl: shared.tokenUrl,
+            responseType:   "code"
+        )
+        if let c = credential {
+            oauth.client.credential.oauthToken          = c.oauthToken
+            oauth.client.credential.oauthTokenSecret    = c.oauthTokenSecret
+            oauth.client.credential.oauthTokenExpiresAt = c.oauthTokenExpiresAt
+            oauth.client.credential.oauthRefreshToken   = c.oauthRefreshToken
         }
+        if let p = profile, let c = credential {
+            CloudAPIClient.login(profile: p, token: c.oauthToken)
+        }
+        shared.manager.retrier = FeedlyOAuthRequestRetrier(oauth)
         CloudAPIClient.sharedPipe.0.observeResult({ result in
             guard let event = result.value else { return }
             switch event {
             case .Login(let profile):
                 self.profile = profile
             case .Logout:
-                if self.isExpired {
-                    self.refreshAccessToken(self.account!)
-                } else {
-                    self.clearAllAccount()
-                }
+                self.profile = nil
+                self.credential = nil
             }
         })
     }
 }
-
-open class FeedlyOAuth2ClientDelegate: NSObject, NXOAuth2ClientDelegate {
-    public override init() {
-    }
-    open func oauthClientNeedsAuthentication(_ client: NXOAuth2Client!) {}
-    open func oauthClientDidGetAccessToken(_ client: NXOAuth2Client!) {}
-    open func oauthClient(_ client: NXOAuth2Client!, didFailToGetAccessTokenWithError error: Error!) {
-    }
-    open func oauthClientDidLoseAccessToken(_ client: NXOAuth2Client!) {
-    }
-    open func oauthClientDidRefreshAccessToken(_ client: NXOAuth2Client!) {
-        CloudAPIClient.refreshAccount(NXOAuth2Account(accountWith: client.accessToken,
-            accountType: CloudAPIClient.accountType))
-    }
-}

            _profile = profile
        }
    }
    
    public static var account: NXOAuth2Account? {
        get {
            if let a = _account {
                return a
            }
            let store = NXOAuth2AccountStore.sharedStore() as! NXOAuth2AccountStore
            for account in store.accounts as! [NXOAuth2Account] {
                if account.accountType == "Feedly" {
                    _account = account
                    return account
                }
            }
            return nil
        }
    }

    public static var isExpired: Bool {
        if let expiresAt = account?.accessToken.expiresAt {
            return NSDate().compare(expiresAt) != ComparisonResult.orderedAscending
        }
        return false
    }

    public static func refreshAccessToken(_ account: NXOAuth2Account) {
        typealias C = CloudAPIClient
        let oauth2client = NXOAuth2Client(clientID: C.clientId,
                                      clientSecret: C.clientSecret,
                                      authorizeURL: NSURL(string: C.shared.authUrl)! as URL!,
                                          tokenURL: NSURL(string: C.shared.tokenUrl)! as URL!,
                                       accessToken: account.accessToken,
                                     keyChainGroup: C.keyChainGroup,
                                        persistent: true,
                                          delegate: CloudAPIClient.oauth2clientDelegate)
        oauth2client?.refreshAccessToken()
    }

    static func refreshAccount(_ account: NXOAuth2Account) {
        clearAllAccount()
        let store = NXOAuth2AccountStore.sharedStore() as! NXOAuth2AccountStore
        store.addAccount(account)
        if let p = profile, let token = account.accessToken.accessToken {
            CloudAPIClient.login(profile: p, token: token)
        }
    }

    public static var notificationDateComponents: DateComponents? {
        get {

    }

    fileprivate static func clearAllAccount() {
        credential = nil
        logout()
    }
    
    fileprivate static func loadConfig() {
