Skip to content

Commit e06261d

Browse files
authored
Merge pull request LinusU#139 from harrowmykel/master
🌹 Add troubleshooting documentation
2 parents 6034e40 + 48bbf6a commit e06261d

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed

README.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,119 @@ close the window.
113113
Redirection URL passed to the authentication service must be the same as the URL on which the application is running (schema, host, port if necessary) and the path must point to created HTML file, `/auth.html` in this case. The `callbackUrlScheme` parameter of the `authenticate()` method does not take into account, so it is possible to use a schema for native platforms in the code.
114114

115115
For the Sign in with Apple in web_message response mode, postMessage from https://appleid.apple.com is also captured, and the authorization object is returned as a URL fragment encoded as a query string (for compatibility with other providers).
116+
117+
## Troubleshooting
118+
119+
When you use this package for the first time, there are some problems you may have. These are some of the common solutions
120+
121+
### Troubleshooting `callbackUrlScheme`
122+
123+
- `callbackUrlScheme` must be a valid schema string or else this wont work.
124+
- A valid RFC 3986 URL scheme must consist of "a letter and followed by any combination of letters, digits, plus ("+"), period ("."), or hyphen ("-")."
125+
- scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
126+
- This means you can not use underscore "_", space " " or uppercase "ABCDEF...". You can not also start with a number. See [RFC3986#page-17](https://www.rfc-editor.org/rfc/rfc3986#page-17)
127+
- examples of VALID `callbackUrlScheme` are `callback-scheme`, `another.scheme`, `examplescheme`
128+
- examples of INVALID `callbackUrlScheme` are `callback_scheme`,`1another.scheme`, `exampleScheme`
129+
130+
### Troubleshooting Flutter App
131+
132+
- You have to tell the `FlutterWebAuth.authenticate` function what your `callbackUrlScheme` is.
133+
- Example if your `callbackUrlScheme` is `valid-callback-scheme`, your dart code will look like
134+
135+
```dart
136+
import 'package:flutter_web_auth/flutter_web_auth.dart';
137+
138+
// Present the dialog to the user
139+
final result = await FlutterWebAuth.authenticate(url: "https://my-custom-app.com/connect", callbackUrlScheme: "valid-callback-scheme");
140+
```
141+
142+
### Troubleshooting Android
143+
144+
- You are required to update your `AndroidManifest.xml` to include the `com.linusu.flutter_web_auth.CallbackActivity` activity something like
145+
146+
```xml
147+
<manifest>
148+
<application>
149+
150+
<!-- add the com.linusu.flutter_web_auth.CallbackActivity activity -->
151+
<activity android:name="com.linusu.flutter_web_auth.CallbackActivity" >
152+
<intent-filter android:label="flutter_web_auth">
153+
<action android:name="android.intent.action.VIEW" />
154+
<category android:name="android.intent.category.DEFAULT" />
155+
<category android:name="android.intent.category.BROWSABLE" />
156+
<data android:scheme="YOUR_CALLBACK_URL_SCHEME_HERE" />
157+
</intent-filter>
158+
</activity>
159+
160+
</application>
161+
</manifest>
162+
```
163+
164+
- Example of valid `AndroidManifest.xml` with VALID `callbackUrlScheme`. in the example below `valid-callback-scheme` is our `callbackUrlScheme`
165+
166+
```xml
167+
<manifest>
168+
<application>
169+
170+
<activity android:name="com.linusu.flutter_web_auth.CallbackActivity" >
171+
<intent-filter android:label="flutter_web_auth">
172+
<action android:name="android.intent.action.VIEW" />
173+
<category android:name="android.intent.category.DEFAULT" />
174+
<category android:name="android.intent.category.BROWSABLE" />
175+
<data android:scheme="valid-callback-scheme" />
176+
</intent-filter>
177+
</activity>
178+
179+
</application>
180+
</manifest>
181+
```
182+
183+
### Troubleshooting OAuth redirects
184+
185+
- Your OAuth Provider must redirect to the valid `callbackUrlScheme` + `://`. This mean if your `callbackUrlScheme` is `validscheme`, your OAuth Provider must redirect to `validscheme://`
186+
- Example with `php`
187+
```php
188+
<?php
189+
190+
header("Location: validscheme://?data1=value1&data2=value2");
191+
```
192+
193+
### Troubleshooting HTML redirects
194+
195+
- If you are using HTML hyperlinks, it must be a valid `callbackUrlScheme` + `://`. This mean if your `callbackUrlScheme` is `customappname`, your html hyperlink should be `customappname://`
196+
- example with `HTML`
197+
198+
```html
199+
<a href="customappname://?data1=value1&data2=value2">Go Back to App</a>
200+
```
201+
202+
### Troubleshooting passing data to app
203+
204+
- You can pass data back to your app by adding GET query parameters. This means by adding name=value type of data after your `callbackUrlScheme` + `://` + `?`
205+
- example to pass `access-token` to your app a valid url for that could be
206+
207+
```text
208+
my-callback-schema://?access-token=jdu9292s
209+
```
210+
211+
- You can pass multipe data by concatenating with `&`
212+
213+
```text
214+
my-callback-schema://?data1=value1&data2=value2
215+
```
216+
217+
- example to pass `access-token` and `user_id` to your app a valid url for that could be
218+
219+
```text
220+
my-callback-schema://?access-token=jdu9292s&user_id=23
221+
```
222+
223+
- You can get the data in your app by using `Uri.parse(result).queryParameters`
224+
225+
```dart
226+
// Present the dialog to the user
227+
final result = await FlutterWebAuth.authenticate(url: "https://my-custom-app.com/connect", callbackUrlScheme: "valid-callback-scheme");
228+
// Extract token from resulting url
229+
String accessToken = Uri.parse(result).queryParameters['access-token'];
230+
String userId = Uri.parse(result).queryParameters['user_id'];
231+
```

0 commit comments

Comments
 (0)