p2 / OAuth2

OAuth2 framework for macOS and iOS, written in Swift.
Other
1.14k stars 275 forks source link

Implement optional custom User-Agent string for embedded MacOS mode #395

Closed ObscureBug closed 5 months ago

ObscureBug commented 1 year ago

Some sites (e.g. Slack) validate the User-Agent string against their supported browser versions. While Safari is based on WebKit, the User-Agent string sent by WebKit is a sub-set of Safari's. When sites (like Slack) don't include the matching WebKit's specific User-Agent in their authentication logic, they reject the connection attempt with "Unsupported browser".

In this specific case, Slack said to override the User-Agent, so here we are.

This situation occurs for embedded mode on MacOS. The change adds an optional configuration parameter that uses the WkWebView API to override the default as follows:

oauth2.customUserAgent = "Version/15.6.1 Safari"
// or in your settings:
"custom_user_agent": "Your string of choice"