The sample already does that. The trick is to have a registered client ID and have a redirect URL set to the native app. Register your app if you haven't already, and add your own redirect URI, or add urn:ietf:wg:oauth:2.0:oob to use the hosted redirect page back to your app on ArcGIS Online. The urn:ietf:wg:oauth:2.0:oob URI is also automatically set for any apps made and registered in AppStudio for ArcGIS Desktop Edition.
We have implemented that in the MapViewer OAuth2View.qml using the Runtime AuthenticationManager