Skip to content

Commit

Permalink
Make sure we only handle urls that are for Strava and not any url con…
Browse files Browse the repository at this point in the history
…taining a code too

(Foursquare redirect urls also contain a code for example)
  • Loading branch information
Ludovic Landry committed Oct 22, 2019
1 parent bb00c39 commit 40ab956
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Sources/StravaSwift/StravaClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,12 @@ extension StravaClient: ASWebAuthenticationPresentationContextProviding {
Helper method to get the code from the redirection from Strava after the user has authorized the application (useful in AppDelegate)
- Parameter url the url returned by Strava through the (ASWeb/SF)AuthenricationSession or application open options.
- Returns: a boolean that indicates if this url has a code and is been handled
- Returns: a boolean that indicates if this url is for Strava, has a code and can be handled properly
**/
public func handleAuthorizationRedirect(_ url: URL) -> Bool {
if url.getQueryParameters()?["code"] != nil {
if let redirectUri = config?.redirectUri, url.absoluteString.starts(with: redirectUri),
let params = url.getQueryParameters(), params["code"] != nil, params["scope"] != nil, params["state"] == "ios" {

self.handleAuthorizationRedirect(url) { result in
if let currentAuthorizationHandler = self.currentAuthorizationHandler {
currentAuthorizationHandler(result)
Expand Down Expand Up @@ -190,6 +192,7 @@ extension StravaClient: ASWebAuthenticationPresentationContextProviding {
result(.failure(error))
}
}

/**
Refresh an OAuth token from Strava
Expand Down

0 comments on commit 40ab956

Please sign in to comment.