-
Notifications
You must be signed in to change notification settings - Fork 11
[New] Authenticate with token #613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Shared/Samples/Authenticate with token/AuthenticateWithTokenView.swift
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good once the questions are answered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done with first pass
Shared/Samples/Authenticate with token/AuthenticateWithTokenView.swift
Outdated
Show resolved
Hide resolved
Shared/Samples/Authenticate with token/AuthenticateWithTokenView.swift
Outdated
Show resolved
Hide resolved
Shared/Samples/Authenticate with token/AuthenticateWithTokenView.swift
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make changes based on other auth samples for setting up and tearing down authenticator.
Shared/Samples/Authenticate with token/AuthenticateWithTokenView.swift
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for making all the changes
Removed Mark as a reviewer as he is out of office today. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only thing that needs to authenticate is the traffic layer. I'll have to think about a way to simplify this.
Shared/Samples/Authenticate with token/AuthenticateWithTokenView.swift
Outdated
Show resolved
Hide resolved
Shared/Samples/Authenticate with token/AuthenticateWithTokenView.swift
Outdated
Show resolved
Hide resolved
Shared/Samples/Authenticate with token/AuthenticateWithTokenView.swift
Outdated
Show resolved
Hide resolved
I think this sample can be simplified with something like this, which just looks at the layer view state and shows an error: struct AuthenticateWithTokenView: View {
/// The authenticator to handle authentication challenges.
@StateObject private var authenticator = Authenticator()
@State private var map = {
// The portal to authenticate with named user.
let portal = Portal(url: .portal, connection: .authenticated)
// The portal item to be displayed on the map.
let portalItem = PortalItem(
portal: portal,
id: .trafficMap
)
// Creates map with portal item.
return Map(item: portalItem)
}()
@State private var error: Error?
var body: some View {
MapView(map: map)
.onLayerViewStateChanged { layer, layerViewState in
if layerViewState.status == .error {
error = layer.loadError
}
}
.errorAlert(presentingError: $error)
.authenticator(authenticator)
.onAppear {
setupAuthenticator()
}
.onDisappear {
Task {
// Reset the challenge handlers and clear credentials
// when the view disappears so that user is prompted to enter
// credentials every time the sample is run, and to clean
// the environment for other samples.
await teardownAuthenticator()
}
}
}
} You might want to fixup the error alert to say what you are looking for it to say with the auth error. And you could also check the layer name or that it's the first operational layer before setting the error. |
@rolson Thanks I applied your suggestion.
This map has only one operational layer, so checking the name may not be necessary.
Here is what the error alerts looks like when the user cancels authentication and when authentication fails due to invalid credentials respectively: ![]() ![]() |
You can fixup the error to show what you want if you like the strings you had before. I just didn't go through that exercise. |
Well, if you are only looking to show an error when the operational layer fails, then you might want to check that the layer is the first operational layer in your map before setting the error. |
Shared/Samples/Authenticate with token/AuthenticateWithTokenView.swift
Outdated
Show resolved
Hide resolved
I used a string before since a standalone view with Text was shown for the error. The refactor uses an errorAlert, which requires an Error. I'm ok leaving this as-is and only using an alert for the error. |
Description
This PR implements
Authenticate with token
inCloud and Portal
category.URL to README: URL
Linked Issue(s)
swift/issues/6858
How To Test
Screenshots