Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(DOCSP-34288) Add User.Changed content and example #3106

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions examples/dotnet/Examples/WorkWithRealm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ public async System.Threading.Tasks.Task Setup()
};

app = App.Create(appConfig);

// :snippet-start: observe-auth-change
app.CurrentUser.Changed += (change, _) =>
{
Debug.WriteLine($"Auth change: {change}, {_}");
// :remove-start:
Assert.IsInstanceOf<System.EventArgs>(_);
// :remove-end:
};
// :snippet-end:

user = await app.LogInAsync(Config.EPCreds);
return;
}
Expand Down
67 changes: 67 additions & 0 deletions examples/dotnet/scripts/bluehawk-one.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

#! /bin/bash

# Use colors in terminal messages: https://notesontech.com/bash-text-formatting/
### Text formatting ###

CLEAR="\x1B[0m"

# Text settings.
BOLD="\x1B[1m"

# Text color.
RED="\x1B[31m"
GREEN="\x1B[32m"
YELLOW="\x1B[33m"

# Background color with bold font.
RED_BG_BOLD="\x1B[1;41m"
GREEN_BG_BOLD="\x1B[1;42m"

### End of text formatting ###

### Work with flags ###
while getopts ":f:" option; do
case $option in
f)
FILE_NAME="$OPTARG"
;;
*)
echo "Usage: $0 [-f FILE_NAME]"
exit 1
;;
esac
done

PROJECT=$(git rev-parse --show-toplevel)
OUTPUT_DIRECTORY=$PROJECT/source/examples/generated/dotnet
INPUT_FILE=$(find $PROJECT/examples/dotnet/Examples -type f -print | grep -i $FILE_NAME)
FILE_EXTENSION="${FILE_NAME##*.}"
BASE_FILE_NAME="${FILE_NAME%.*}"

if [[ -n $INPUT_FILE ]]
then
# Bluehawk a single file
echo "${GREEN_BG_BOLD} Bluehawk: ${CLEAR} ${GREEN}Generate samples from '$FILE_NAME' ${CLEAR}"

npx bluehawk snip $INPUT_FILE -o $OUTPUT_DIRECTORY

# TODO: There's probably a more idiomatic way to do this results filtering.
GENERATED_FILES=$(find $OUTPUT_DIRECTORY -type f | grep -i $BASE_FILE_NAME)
FILTERED_FILES=$(find $GENERATED_FILES -type f -not -name "*.rst")
FILES_TO_REMOVE=$(find $FILTERED_FILES -type f -name "*.$FILE_EXTENSION")

echo "
${YELLOW}Removing matching non-.rst snippet files generated by Bluehawk:${CLEAR}
$FILES_TO_REMOVE"
echo "
${YELLOW}From:${CLEAR} $OUTPUT_DIRECTORY"

# Delete matching non-.rst snippet file generated by Bluehawk.
find $FILTERED_FILES -type f -name "*.$FILE_EXTENSION" -delete

echo "
${GREEN_BG_BOLD} Bluehawk: ${CLEAR} Complete!"
else
echo -e "${RED_BG_BOLD} Couldn't find '${FILE_NAME}'."
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
app.CurrentUser.Changed += (change, _) =>
{
Debug.WriteLine($"Auth change: {change}, {_}");
};
24 changes: 23 additions & 1 deletion source/sdk/dotnet/manage-users/authenticate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
Authenticate Users - .NET SDK
=============================

.. meta::
:description: Authenticate users in many ways with the Atlas Device SDK for .NET.

.. facet::
:name: genre
:values: tutorial

.. contents:: On this page
:local:
:backlinks: none
Expand Down Expand Up @@ -177,4 +184,19 @@ Refresh Token Expiration
------------------------

.. include:: /includes/refresh-token-expiry.rst



Observe Authentication Changes
------------------------------

.. versionadded:: v11.6.0

You can observe a flow of authentication change events by calling
:dotnet-sdk:`User.Changed() <reference/Realms.Sync.User.html#Realms_Sync_User_Changed>`
on a valid user object.

Currently, ``User.Changed()`` triggers on all user events and you should add a
handler to ensure your responses to events are idempotent.

.. literalinclude:: /examples/generated/dotnet/WorkWithRealm.snippet.observe-auth-change.cs
:language: csharp
Loading