Skip to content

Commit 0c7714c

Browse files
committed
Update Browser API documentation with new methods and improved structure
- Add system() method for opening URLs in device's default browser - Add auth() method for OAuth authentication flows with nativephp:// handling - Update inApp() method description with platform-specific details - Add comprehensive use cases for each browser method - Include platform behavior notes for iOS and Android implementations - Remove redundant sections and streamline documentation - Update examples to demonstrate all three browser methods
1 parent 14bbdf7 commit 0c7714c

File tree

1 file changed

+29
-50
lines changed

1 file changed

+29
-50
lines changed

resources/views/docs/mobile/1/apis/browser.md

Lines changed: 29 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ order: 250
55

66
## Overview
77

8-
The Browser API allows you to open URLs in an in-app browser that is "owned" by your application. This is essential when working with OAuth redirects since you need to provide a redirect URL that would naturally open in the user's default browser.
8+
The Browser API provides three methods for opening URLs in mobile apps, each designed for specific use cases: in-app browsing, system browser navigation, and OAuth authentication flows.
99

1010
```php
1111
use Native\Mobile\Facades\Browser;
@@ -15,72 +15,51 @@ use Native\Mobile\Facades\Browser;
1515

1616
### `inApp()`
1717

18-
Opens a URL in an in-app browser window.
19-
20-
**Parameters:**
21-
- `string $url` - The URL to open in the in-app browser
18+
Opens a URL in an embedded browser within your app using Custom Tabs (Android) or SFSafariViewController (iOS).
2219

2320
```php
2421
Browser::inApp('https://nativephp.com/mobile');
2522
```
2623

27-
## Use Cases
28-
29-
### OAuth Authentication
24+
### `system()`
3025

31-
The in-app browser is particularly useful for OAuth flows where you need to:
32-
- Redirect users to a third-party authentication provider
33-
- Capture the redirect URL after authentication
34-
- Return control to your app seamlessly
26+
Opens a URL in the device's default browser app, leaving your application entirely.
3527

3628
```php
37-
use Native\Mobile\Facades\Browser;
38-
39-
class AuthController extends Component
40-
{
41-
public function authenticateWithProvider()
42-
{
43-
// Open OAuth provider in in-app browser
44-
Browser::inApp('https://provider.com/oauth/authorize?client_id=your_client_id&redirect_uri=your_app_scheme://oauth/callback');
45-
}
46-
}
29+
Browser::system('https://nativephp.com/mobile');
4730
```
4831

49-
### External Content
32+
### `auth()`
5033

51-
Display external content while keeping users within your app:
34+
Opens a URL in a specialized authentication browser designed for OAuth flows with automatic `nativephp://` redirect handling.
5235

5336
```php
54-
// Open documentation
55-
Browser::inApp('https://docs.example.com/help');
37+
Browser::auth('https://provider.com/oauth/authorize?client_id=123&redirect_uri=nativephp://127.0.0.1/auth/callback');
38+
```
5639

57-
// Open terms of service
58-
Browser::inApp('https://example.com/terms');
40+
## Use Cases
5941

60-
// Open privacy policy
61-
Browser::inApp('https://example.com/privacy');
62-
```
42+
### When to Use Each Method
6343

64-
## Integration with Deep Links
44+
**`inApp()`** - Keep users within your app experience:
45+
- Documentation, help pages, terms of service
46+
- External content that relates to your app
47+
- When you want users to easily return to your app
6548

66-
Use the in-app browser in conjunction with App/Universal/Deep links for complete OAuth flows:
49+
**`system()`** - Full browser experience needed:
50+
- Complex web applications
51+
- Content requiring specific browser features
52+
- When users need bookmarking or sharing capabilities
6753

68-
1. **Open OAuth provider** - Use `Browser::inApp()` to start authentication
69-
2. **User authenticates** - User completes authentication in the in-app browser
70-
3. **Redirect to app** - OAuth provider redirects to your app's deep link
71-
4. **Handle in app** - Your app receives the deep link and processes the authentication
54+
**`auth()`** - OAuth authentication flows:
55+
- Login with WorkOS, Auth0, Google, Facebook, etc.
56+
- Secure authentication with automatic redirects
57+
- Isolated browser session for security
7258

73-
```php
74-
use Native\Mobile\Facades\Browser;
75-
use Livewire\Attributes\On;
76-
use Native\Mobile\Events\DeepLink\Received;
77-
78-
class OAuthHandler extends Component
79-
{
80-
public function startOAuth()
81-
{
82-
Browser::inApp('https://github.com/login/oauth/authorize?client_id=your_client_id&redirect_uri=myapp://oauth/callback');
83-
}
84-
}
85-
```
59+
## Platform Behavior
60+
61+
- **iOS**: Uses SFSafariViewController (inApp), Safari (system), ASWebAuthenticationSession (auth)
62+
- **Android**: Uses Custom Tabs (inApp), default browser (system), Custom Tabs with auth handling (auth)
63+
64+
The Browser API provides the right tool for each browsing scenario in your mobile application.
8665

0 commit comments

Comments
 (0)