Skip to content

Commit 103d04a

Browse files
committed
add mobile snippets
1 parent 75b1632 commit 103d04a

File tree

1 file changed

+107
-3
lines changed
  • src/pages/[platform]/build-a-backend/auth/examples/microsoft-entra-id-saml

1 file changed

+107
-3
lines changed

src/pages/[platform]/build-a-backend/auth/examples/microsoft-entra-id-saml/index.mdx

Lines changed: 107 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,16 +222,120 @@ signInWithRedirect({
222222
</InlineFilter>
223223
<InlineFilter filters={["android"]}>
224224

225-
{/* @todo */}
225+
{/* @todo update with explicit provider name */}
226+
227+
<BlockSwitcher>
228+
<Block name="Java">
229+
230+
```java
231+
Amplify.Auth.signInWithWebUI(
232+
this,
233+
result -> Log.i("AuthQuickStart", result.toString()),
234+
error -> Log.e("AuthQuickStart", error.toString())
235+
);
236+
```
237+
238+
</Block>
239+
<Block name="Kotlin - Callbacks">
240+
241+
```kotlin
242+
Amplify.Auth.signInWithWebUI(
243+
this,
244+
{ Log.i("AuthQuickStart", "Signin OK = $it") },
245+
{ Log.e("AuthQuickStart", "Signin failed", it) }
246+
)
247+
```
248+
249+
</Block>
250+
<Block name="Kotlin - Coroutines">
251+
252+
```kotlin
253+
try {
254+
val result = Amplify.Auth.signInWithWebUI(this)
255+
Log.i("AuthQuickStart", "Signin OK: $result")
256+
} catch (error: AuthException) {
257+
Log.e("AuthQuickStart", "Signin failed", error)
258+
}
259+
```
260+
261+
</Block>
262+
<Block name="RxJava">
263+
264+
```java
265+
RxAmplify.Auth.signInWithWebUI(this)
266+
.subscribe(
267+
result -> Log.i("AuthQuickStart", result.toString()),
268+
error -> Log.e("AuthQuickStart", error.toString())
269+
);
270+
```
271+
272+
</Block>
273+
</BlockSwitcher>
226274

227275
</InlineFilter>
228276
<InlineFilter filters={["flutter"]}>
229277

230-
{/* @todo */}
278+
```dart
279+
Future<void> signInWithMicrosoftEntraID() async {
280+
try {
281+
final result = await Amplify.Auth.signInWithWebUI(
282+
provider: AuthProvider.custom("MicrosoftEntraIDSAML"),
283+
);
284+
safePrint('Sign in result: $result');
285+
} on AuthException catch (e) {
286+
safePrint('Error signing in: ${e.message}');
287+
}
288+
}
289+
```
231290

232291
</InlineFilter>
233292
<InlineFilter filters={["swift"]}>
234293

235-
{/* @todo */}
294+
<BlockSwitcher>
295+
<Block name="Async/Await">
296+
297+
```swift
298+
func signInWithMicrosoftEntraID() async {
299+
do {
300+
let signInResult = try await Amplify.Auth.signInWithWebUI(
301+
for: AuthProvider.custom("MicrosoftEntraIDSAML"),
302+
presentationAnchor: self.view.window!
303+
)
304+
if signInResult.isSignedIn {
305+
print("Sign in succeeded")
306+
}
307+
} catch let error as AuthError {
308+
print("Sign in failed \(error)")
309+
} catch {
310+
print("Unexpected error: \(error)")
311+
}
312+
}
313+
```
314+
315+
</Block>
316+
<Block name="Combine">
317+
318+
```swift
319+
func signInWithMicrosoftEntraID() -> AnyCancellable {
320+
Amplify.Publisher.create {
321+
try await Amplify.Auth.signInWithWebUI(
322+
for: AuthProvider.custom("MicrosoftEntraIDSAML"),
323+
presentationAnchor: self.view.window!
324+
)
325+
}
326+
.sink { completion in
327+
if case let .failure(authError) = completion {
328+
print("Sign in failed \(authError)")
329+
}
330+
} receiveValue: { signInResult in
331+
if signInResult.isSignedIn {
332+
print("Sign in succeeded")
333+
}
334+
}
335+
}
336+
```
337+
338+
</Block>
339+
</BlockSwitcher>
236340

237341
</InlineFilter>

0 commit comments

Comments
 (0)