Skip to content

Instantly share code, notes, and snippets.

@AlexandreCools
Last active February 25, 2021 13:13
Show Gist options
  • Select an option

  • Save AlexandreCools/096a5e1b081a4df1731d0cd6dd58f72b to your computer and use it in GitHub Desktop.

Select an option

Save AlexandreCools/096a5e1b081a4df1731d0cd6dd58f72b to your computer and use it in GitHub Desktop.
[MEDIUM] Strava API - Access & Refresh token - iOS 13, Swift 5 - Step 2
import UIKit
import AuthenticationServices
class ViewController: UIViewController {
private var authSession: ASWebAuthenticationSession?
private let clientId: String = "11111"
private let urlScheme: String = "youUrlScheme"
private let fallbackUrl: String = "yourFallbackUrl.com"
@IBAction private func connectToStrava(_ sender: UIButton) {
presentStravaAuthentication()
}
private func presentStravaAuthentication() {
let url: String = "https://www.strava.com/oauth/mobile/authorize?client_id=\(clientId)&redirect_uri=\(urlScheme)%3A%2F%2F\(fallbackUrl)&response_type=code&approval_prompt=auto&scope=read"
guard let authenticationUrl = URL(string: url) else { return }
authSession = ASWebAuthenticationSession(url: authenticationUrl, callbackURLScheme: "\(urlScheme)://") { url, error in
if let error = error {
print(error)
} else {
if let url = url {
print(url)
}
}
}
authSession?.presentationContextProvider = self
authSession?.start()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment