Skip to content

Commit 6f1d2bc

Browse files
committed
support local conn with no auth and via http
1 parent fc053ec commit 6f1d2bc

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

src/Extensions/Azure/DurableTaskSchedulerExtensions.cs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ static GrpcChannel GetGrpcChannelForOptions(DurableTaskSchedulerOptions options)
7070
throw RequiredOptionMissing(nameof(options.TaskHubName));
7171
}
7272

73-
TokenCredential credential = options.Credential ?? throw RequiredOptionMissing(nameof(options.Credential));
74-
7573
string taskHubName = options.TaskHubName;
7674
string endpoint = options.EndpointAddress;
7775

@@ -112,17 +110,35 @@ options.Credential is not null
112110
metadata.Add("Authorization", $"Bearer {token.Token}");
113111
});
114112

113+
// Production will use HTTPS, but local testing will use HTTP
114+
ChannelCredentials channelCreds = endpoint.StartsWith("https://") ?
115+
ChannelCredentials.SecureSsl :
116+
ChannelCredentials.Insecure;
115117
#if NET6_0
116-
return GrpcChannel.ForAddress(
117-
endpoint,
118-
new GrpcChannelOptions
118+
return GrpcChannel.ForAddress(this.options.Address, new GrpcChannelOptions
119119
{
120-
Credentials = ChannelCredentials.Create(ChannelCredentials.SecureSsl, managedBackendCreds),
120+
// The same credential is being used for all operations.
121+
// https://learn.microsoft.com/aspnet/core/grpc/authn-and-authz#set-the-bearer-token-with-callcredentials
122+
Credentials = ChannelCredentials.Create(channelCreds, managedBackendCreds),
123+
124+
// TODO: This is not appropriate for use in production settings. Setting this to true should
125+
// only be done for local testing. We should hide this setting behind some kind of flag.
126+
UnsafeUseInsecureChannelCallCredentials = true,
121127
});
122128
#else
123129
return new GrpcChannel(
124130
endpoint,
125-
ChannelCredentials.Create(ChannelCredentials.SecureSsl, managedBackendCreds));
131+
ChannelCredentials.Create(channelCreds, managedBackendCreds),
132+
new GrpcChannelOptions
133+
{
134+
// The same credential is being used for all operations.
135+
// https://learn.microsoft.com/aspnet/core/grpc/authn-and-authz#set-the-bearer-token-with-callcredentials
136+
Credentials = ChannelCredentials.Create(channelCreds, managedBackendCreds),
137+
138+
// TODO: This is not appropriate for use in production settings. Setting this to true should
139+
// only be done for local testing. We should hide this setting behind some kind of flag.
140+
UnsafeUseInsecureChannelCallCredentials = true,
141+
});
126142
#endif
127143
}
128144

0 commit comments

Comments
 (0)