@@ -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