You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 29, 2023. It is now read-only.
You can use OAuth in your Flutter application, but some platforms like Android and Apple requires additional configuration to enable the OAuth callback, so the your users can be redirected back to your app..
48
+
49
+
#### Android OAuth callback
50
+
51
+
In order to capture the Appwrite OAuth callback url, the following activity needs to be added inside the `<application>` tag, along side the existing `<activity>` tags in your `AndroidManifest.xml`. Be sure to replace the `[PROJECT_ID]` string with your actual Appwrite project ID. You can find your Appwrite project ID in your project settings screen in your Appwrite console.
52
+
53
+
```xml
54
+
<manifest ...>
55
+
...
56
+
<application ...>
57
+
...
58
+
<!-- Add this inside the `<application>` tag, along side the existing `<activity>` tags -->
In order to capture the Appwrite OAuth callback url, the following URL scheme needs to added to your `Info.plist`
73
+
```xml
74
+
<key>CFBundleURLTypes</key>
75
+
<array>
76
+
<dict>
77
+
<key>CFBundleTypeRole</key>
78
+
<string>Editor</string>
79
+
<key>CFBundleURLName</key>
80
+
<string>io.appwrite</string>
81
+
<key>CFBundleURLSchemes</key>
82
+
<array>
83
+
<string>appwrite-callback-[PROJECT_ID]</string>
84
+
</array>
85
+
</dict>
86
+
</array>
87
+
```
47
88
48
-
For Flutter make sure to follow [getting started for Flutter](https://appwrite.io/docs/getting-started-for-flutter#addYourPlatform) and setup configuration required for each platform to successfully authenticate user with OAuth2 providers.
89
+
To authenticate a user in your Flutter application, use the [Create OAuth2 Session](https://appwrite.io/docs/client/account?sdk=flutter-default#accountCreateOAuth2Session) endpoint.
49
90
50
91
```dart
51
92
import 'package:appwrite/appwrite.dart';
@@ -67,11 +108,141 @@ void main() async {
67
108
```
68
109
69
110
### Android (Kotlin)
111
+
Before you can add OAuth to your Android app, you need to setup a callback for your OAuth flow.
112
+
113
+
In order to capture the Appwrite OAuth callback url, the following activity needs to be added inside the `<application>` tag, along side the existing `<activity>` tags in your `AndroidManifest.xml`. Be sure to replace the `[PROJECT_ID]` string with your actual Appwrite project ID. You can find your Appwrite project ID in your project settings screen in your Appwrite console.
114
+
115
+
```xml
116
+
<manifest ...>
117
+
...
118
+
<application ...>
119
+
...
120
+
<!-- Add this inside the `<application>` tag, along side the existing `<activity>` tags -->
To authenticate a user in your Android application, use the [Create OAuth2 Session](https://appwrite.io/docs/client/account?sdk=android-kotlin#accountCreateOAuth2Session) endpoint.
134
+
135
+
```kotlin
136
+
importio.appwrite.Client
137
+
importio.appwrite.services.Account
138
+
139
+
val client =Client(context)
140
+
.setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
141
+
.setProject("[PROJECT_ID]") // Your project ID
142
+
143
+
val account =Account(client)
144
+
145
+
account.createOAuth2Session(
146
+
provider ="github",
147
+
)
148
+
```
70
149
71
150
### Android (Java)
151
+
Before you can add OAuth to your Android app, you need to setup a callback for your OAuth flow.
152
+
153
+
In order to capture the Appwrite OAuth callback url, the following activity needs to be added inside the `<application>` tag, along side the existing `<activity>` tags in your `AndroidManifest.xml`. Be sure to replace the `[PROJECT_ID]` string with your actual Appwrite project ID. You can find your Appwrite project ID in your project settings screen in your Appwrite console.
154
+
155
+
```xml
156
+
<manifest ...>
157
+
...
158
+
<application ...>
159
+
...
160
+
<!-- Add this inside the `<application>` tag, along side the existing `<activity>` tags -->
To authenticate a user in your Android application, use the [Create OAuth2 Session](https://appwrite.io/docs/client/account?sdk=android-java#accountCreateOAuth2Session) endpoint.
174
+
175
+
```java
176
+
importio.appwrite.Client;
177
+
importio.appwrite.coroutines.CoroutineCallback;
178
+
importio.appwrite.services.Account;
179
+
180
+
Client client =newClient(context)
181
+
.setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
182
+
.setProject("[PROJECT_ID]"); // Your project ID
183
+
184
+
Account account =newAccount(client);
185
+
186
+
account.createOAuth2Session(
187
+
"github",
188
+
newCoroutineCallback<>((result, error) -> {
189
+
if (error !=null) {
190
+
error.printStackTrace();
191
+
return;
192
+
}
193
+
194
+
Log.d("Appwrite", result.toString());
195
+
})
196
+
);
197
+
```
72
198
73
199
### iOS (Swift)
74
200
201
+
In order to capture the Appwrite OAuth callback url, the following URL scheme needs to added to your `Info.plist`
202
+
```xml
203
+
<key>CFBundleURLTypes</key>
204
+
<array>
205
+
<dict>
206
+
<key>CFBundleTypeRole</key>
207
+
<string>Editor</string>
208
+
<key>CFBundleURLName</key>
209
+
<string>io.appwrite</string>
210
+
<key>CFBundleURLSchemes</key>
211
+
<array>
212
+
<string>appwrite-callback-[PROJECT_ID]</string>
213
+
</array>
214
+
</dict>
215
+
</array>
216
+
```
217
+
218
+
If you're using UIKit, you'll also need to add a hook to your `SceneDelegate.swift` file to ensure cookies work correctly.
To authenticate a user in your Android application, use the [Create OAuth2 Session](https://appwrite.io/docs/client/account?sdk=apple-default#accountCreateOAuth2Session) endpoint.
230
+
231
+
```swift
232
+
importAppwrite
233
+
234
+
let client =Client()
235
+
.setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
236
+
.setProject("[PROJECT_ID]") // Your project ID
237
+
238
+
let account =Account(client)
239
+
240
+
let success =tryawait account.createOAuth2Session(
241
+
provider: "github"
242
+
)
243
+
244
+
```
245
+
75
246
## Refreshing the OAuth2 session
76
247
OAuth2 sessions expire to protect from security risks. This means, OAuth2 sessions should be refreshed to keep the user authenticated. You can do this by calling the [Update OAuth Session](https://appwrite.io/docs/client/account#accountUpdateSession) endpoint when ever your user visits your app.
77
248
@@ -124,7 +295,55 @@ void main() async {
124
295
```
125
296
126
297
### Android (Kotlin)
298
+
```kotlin
299
+
importio.appwrite.Client
300
+
importio.appwrite.services.Account
127
301
128
-
### Android (Java)
302
+
val client =Client(context)
303
+
.setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
304
+
.setProject("[PROJECT_ID]") // Your project ID
305
+
306
+
val account =Account(client)
129
307
308
+
val response = account.updateSession(
309
+
sessionId ="current"
310
+
)
311
+
```
312
+
### Android (Java)
313
+
```java
314
+
importio.appwrite.Client;
315
+
importio.appwrite.coroutines.CoroutineCallback;
316
+
importio.appwrite.services.Account;
317
+
318
+
Client client =newClient(context)
319
+
.setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
320
+
.setProject("[PROJECT_ID]"); // Your project ID
321
+
322
+
Account account =newAccount(client);
323
+
324
+
account.updateSession(
325
+
"current"
326
+
newCoroutineCallback<>((result, error) -> {
327
+
if (error !=null) {
328
+
error.printStackTrace();
329
+
return;
330
+
}
331
+
332
+
Log.d("Appwrite", result.toString());
333
+
})
334
+
);
335
+
```
130
336
### iOS (Swift)
337
+
```swift
338
+
importAppwrite
339
+
340
+
let client =Client()
341
+
.setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
0 commit comments