Get unexpired access token #2
Comments
You can get the current Access Token by initializing a You would do: let tokens = try Tokens.init(for: clientIDString, from: keychainInstance)
let accessToken = tokens.accessToken That initializer is documented here: https://github.com/Colaski/SwAuth/blob/main/Sources/SwAuth/Tokens.swift#L82. I see your original title asks about refreshing the token manually, I'm curious about why you would want to do that. |
Thanks for your answer. Thats why I didnt found that in the documentation. I guess I ask wrong. I want to access an unexpired access token, without calling a request for it to be fresh. I using the accessToken inside a webView so I need it to be unexpired. I will try your code later on :) thanks |
My apologies, I miss-understood. Just to clarify, the I can maybe refactor the code to do as you describe. |
@dungi turns out no refractor required. What you should be able to do is call the Here's an example: var tokens = try Tokens.init(for: clientIDString, from: keychainInstance)
try await someAuthFlowInstance.checkRefreshToken(tokens: &tokens)
// Your instance of Tokens has now been updated accordingly
let accessToken = tokens.accessToken Please reach out if you have an issue or further questions! Apologies for the confusion. |
Hey, at my first try, it doesn't seem that "Token" is reachable. Cause it's not public. I also run into something else, but I will try to fix this myself: |
I just pushed an update (1.0.2) that makes so this should work now: var tokens = try Tokens.init(for: clientIDString, from: keychainInstance)
try await someAuthFlowInstance.checkRefreshToken(tokens: &tokens)
let accessToken = tokens.accessToken Once Xcode 13.2 is officially released I will push an update supporting macOS 10.15, iOS 13, tvOS 13, and watchOS 6. Should be as easy as changing some numbers around. |
I guess in a framework everything that is not public, is not accessible outside of its framework. To access "tokens.accessToken" accessToken inside Token must be public too :) rest looks good for me. Thanks for your fast update. |
Woops, i made the methods public but not the properties, over sight on by part. Thanks for sticking with me 😅. 1.0.3 pushed just now. |
Is your feature request related to a problem? Please describe.
Describe the solution you'd like
The text was updated successfully, but these errors were encountered: