Skip to content

Commit

Permalink
Added missing samples for UserCredentials in appendToStream
Browse files Browse the repository at this point in the history
  • Loading branch information
oskardudycz committed Dec 28, 2020
1 parent 075e013 commit c58bf5c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
13 changes: 12 additions & 1 deletion docs/clients/grpc/appending-events/README.md
Expand Up @@ -109,4 +109,15 @@ This check can be used to implement optimistic concurrency. When you retrieve a
TODO

## User credentials
The credentials used to append the data can be supplied. Please see [here](/authentication/authenticating-with-username-password.html) for more information.
You can provide user credentials to be used to append the data as follows. This will override the default credentials set on the connection.

<xode-group>
<xode-block title="C#">

<<< @/samples/grpc/dotnet/GrpcDocs/Producer.cs#overriding-user-credentials
</xode-block>
<xode-block title="NodeJS">

<<< @/samples/grpc/nodejs/samples/appending-events/index.js#overriding-user-credentials
</xode-block>
</xode-group>
10 changes: 10 additions & 0 deletions samples/grpc/dotnet/GrpcDocs/Producer.cs
Expand Up @@ -40,6 +40,16 @@ protected async Task ExecuteAsync(CancellationToken cancellationToken)
cancellationToken: cancellationToken
);
#endregion appendEvents

#region overriding-user-credentials
await client.AppendToStreamAsync(
"some-stream",
StreamState.Any,
new[] { eventData },
userCredentials: new UserCredentials("admin", "changeit"),
cancellationToken: cancellationToken
);
#endregion overriding-user-credentials
}
}
}
20 changes: 20 additions & 0 deletions samples/grpc/nodejs/samples/appending-events/index.js
Expand Up @@ -113,3 +113,23 @@ export async function appendWithConcurrencyCheck(client) {
});
// endregion append-with-concurrency-check
}

export async function appendWithNoStreamOverridingCredentials(client) {
const event = jsonEvent({
id: uuid(),
eventType: "some-event",
payload: {
id: "1",
value: "some value",
},
});
// region overriding-user-credentials
const credentials = {
username: "admin",
password: "changeit",
};
await client.appendToStream("some-stream", event, {
credentials
});
// endregion overriding-user-credentials
}

0 comments on commit c58bf5c

Please sign in to comment.