# OAuth Flow in IOS always redirects me to twitch.tv

**URL:** <https://discuss.dev.twitch.com/t/oauth-flow-in-ios-always-redirects-me-to-twitch-tv/24515>\
**Category:** API\
**Created:** [March 19, 2020, 3:57pm UTC](https://discuss.dev.twitch.com/t/oauth-flow-in-ios-always-redirects-me-to-twitch-tv/24515 "2020-03-19T15:57:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pierluigi\_Rizzu](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/pierluigi_rizzu/32/8127_2.png) [@Pierluigi\_Rizzu](https://discuss.dev.twitch.com/u/Pierluigi_Rizzu)\
**Post date:** [March 19, 2020, 3:57pm UTC](https://discuss.dev.twitch.com/t/oauth-flow-in-ios-always-redirects-me-to-twitch-tv/24515/1 "2020-03-19T15:57:27Z")

</div>

As title says.  
I login, build the url and loading it a safariviewcontroller. The authorization screen of the app doesn’t appear, instead it makes me login in twitch and then BOM! It redirects me to the [twitch.tv](http://twitch.tv) homepage lol  
This is my code to provide the URL.  
static public let shared = TwitchAPI()

static let clientID = “XXXX”  
static let secretKey = “XXXX”  
static let redirectURL = “XXX”  
static let scopes = “user\_subscriptions”

static let baseURL = “[https://api.twitch.tv/](https://api.twitch.tv/)” / **I’ll use this URL for every NON OAUTH Request.** /  
static let oauthURL = “[https://id.twitch.tv/oauth2](https://id.twitch.tv/oauth2)” / **The OAuth2 endpoint’ll be used during the authentication flow.** /  
public var loginURL: URL = {  
var urlComponents = URLComponents(string: “(TwitchAPI.oauthURL)/authorize” )!

```
urlComponents.queryItems = [
    URLQueryItem(name: "client_id", value: TwitchAPI.clientID),
    URLQueryItem(name: "redirect_uri", value: TwitchAPI.redirectURL),
    URLQueryItem(name: "response_type", value: "code"),
    URLQueryItem(name: "scope", value: "viewing_activity_read")
]

let url = urlComponents.url
return url!
}()
```

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [March 19, 2020, 7:57pm UTC](https://discuss.dev.twitch.com/t/oauth-flow-in-ios-always-redirects-me-to-twitch-tv/24515/2 "2020-03-19T19:57:01Z")

</div>

Closed on March 19, 2020, 7:57pm UTC


