     }
 
     public static func clearAllAccount() {
-        let store = NXOAuth2AccountStore.sharedStore() as! NXOAuth2AccountStore
-        for account in store.accounts as! [NXOAuth2Account] {
-            if account.accountType == APIClient.keyChainGroup {
-                store.removeAccount(account)
-            }
-        }
-        _account = nil
+        credential = nil
         SoundCloudKit.APIClient.accessToken = nil
     }
 
-    static func refreshAccount(_ account: NXOAuth2Account) {
-        clearAllAccount()
-        let store = NXOAuth2AccountStore.sharedStore() as! NXOAuth2AccountStore
-        store.addAccount(account)
-        SoundCloudKit.APIClient.accessToken = account.accessToken.accessToken
-    }
-
     public class func setup() {
-        APIClient.oauth2clientDelegate = OAuth2ClientDelegate()
         loadConfig()
-        if let _ = SoundCloudKit.APIClient.me {
-            SoundCloudKit.APIClient.accessToken = account?.accessToken.accessToken
-        } else {
-            SoundCloudKit.APIClient.clearAllAccount()
-        }
+        oauth = OAuth2Swift(
+            consumerKey:    clientId,
+            consumerSecret: clientSecret,
+            authorizeUrl:   authUrl,
+            accessTokenUrl: 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
+            APIClient.sharedInstance.manager.session.configuration.httpAdditionalHeaders = ["Authorization": "Bearer \(c.oauthToken)"]
+        }
+        APIClient.sharedInstance.manager.retrier = SoundCloudOAuthRequestRetrier(oauth)
+        APIClient.accessToken = credential?.oauthToken
+    }
+
+    static func authorize(_ viewController: UIViewController, callback: (() -> ())? = nil) {
+        let vc = OAuthViewController()
+        viewController.addChildViewController(vc)
+        oauth.authorizeURLHandler = vc
+        let _ = oauth.authorize(
+            withCallbackURL: URL(string: APIClient.redirectUri)!,
+            scope: APIClient.scope.joined(separator: ","),
+            state: "SoundCloud",
+            success: { credential, response, parameters in
+                APIClient.credential = credential
+                APIClient.accessToken = credential.oauthToken
+                APIClient.sharedInstance.fetchMe().on(
+                    failed: { error in
+                        if let callback = callback { callback() }
+                }, value: { user in
+                    APIClient.me = user
+                    AppDelegate.shared.reload()
+                    if let callback = callback { callback() }
+                }).start()
+        },
+            failure: { error in
+                if let callback = callback { callback() }
+        })
     }
 
     public class func loadConfig() {

import NXOAuth2Client
import ReactiveSwift
import Alamofire

open class OAuth2ClientDelegate: NSObject, NXOAuth2ClientDelegate {
    public typealias RequestCallback = (DataResponse<Any>) -> Void
    open var pendingRequests: [(APIClient.Router, RequestCallback)]
    public override init() {
        pendingRequests = []
    }
    func addPendingRequest(_ request: APIClient.Router, callback: @escaping RequestCallback) {
        pendingRequests.append((request, callback))
    }
    func restartPendingRequests() {
        for req in pendingRequests {
            APIClient.sharedInstance.manager.request(req.0).responseJSON(options: .allowFragments, completionHandler: req.1)
        }
        pendingRequests = []
    }
    open func oauthClientNeedsAuthentication(_ client: NXOAuth2Client!) {}
    open func oauthClientDidGetAccessToken(_ client: NXOAuth2Client!) {}
    open func oauthClient(_ client: NXOAuth2Client!, didFailToGetAccessTokenWithError error: Error!) {
        restartPendingRequests()
    }
    open func oauthClientDidLoseAccessToken(_ client: NXOAuth2Client!) {}
    open func oauthClientDidRefreshAccessToken(_ client: NXOAuth2Client!) {
        APIClient.refreshAccount(NXOAuth2Account(accountWith: client.accessToken,
                                                 accountType: APIClient.accountType))
        restartPendingRequests()
    }
}


                    observer.sendCompleted()
                }
            }
            disposable.observeEnded {
                req.cancel()
            }
        }
    }

    func fetchItems<T: JSONInitializable>(_ route: Router) -> SignalProducer<[T], NSError> {
        return SignalProducer { observer, disposable in
            let req = self.manager.request(route).validate(statusCode: 200..<300).responseJSON(options: .allowFragments) {(response: DataResponse<Any>) -> Void in
                if let e = response.result.error as NSError? {
                    if let r = response.response {
                        observer.send(error: NSError(domain: e.domain, code: e.code, userInfo: [APIClient.errorResponseKey:r]))
