Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

How can you 'configure' OpenIdConnectOptions CallbackPath? #1230

Closed
MarkPflug opened this issue May 24, 2017 · 10 comments
Closed

How can you 'configure' OpenIdConnectOptions CallbackPath? #1230

MarkPflug opened this issue May 24, 2017 · 10 comments
Assignees

Comments

@MarkPflug
Copy link

I'm trying to set the OpenIdConnectOptions.CallbackPath through appsettings.json configuration, but it throws an exception when I attempt to access the IOptions Value property.

System.InvalidOperationException occurred
  HResult=0x80131509
  Message=Failed to convert '/OpenIdCallback' to type 'Microsoft.AspNetCore.Http.PathString'.
  Source=Microsoft.Extensions.Configuration.Binder
  StackTrace:
   at Microsoft.Extensions.Configuration.ConfigurationBinder.ConvertValue(Type type, String value)
   at Microsoft.Extensions.Configuration.ConfigurationBinder.BindInstance(Type type, Object instance, IConfiguration config)
  ...
Inner Exception 1:
NotSupportedException: TypeConverter cannot convert from System.String.

I can set this value in code, because there is an implicit conversion from string to PathString. Is there a way to set it through configuration?

@HaoK
Copy link
Member

HaoK commented May 24, 2017

Yeah there's no support for PathStrings in the binder yet, I'll file an issue for this in Configuration

@Tratcher
Copy link
Member

What's dynamic about your CallbackPath such that you need to set it from config?

@MarkPflug
Copy link
Author

I can probably get away with the default, for now. However, I would expect that all properties on "Options" types of objects to be able to be initialized via configuration. Perhaps that is a mistaken assumption on my part.

The ultimate goal, is to be able to add new OpenId auth providers purely through configuration. If I have more than one OpenId provider, can they use the same callback endpoint? If not, I'll need to be able to configure it for each provider.

@Tratcher
Copy link
Member

OIDC providers should use unique callback paths.

@MarkPflug
Copy link
Author

Right, that's what I was expecting. So, to accomplish what I'm trying to do I'll need to be able to configure the CallbackPath via configuration, which is not currently possible.
I can work around this, by creating a "configurable" OpenIdConnectOptionsEx class, that simply uses string instead of PathString, and map it at runtime back to an OpenIdConnectOptions instance, but I was hoping to avoid that.
Thanks for the quick responses.

@MarkPflug
Copy link
Author

Nevermind. I found a better solution; register a custom TypeConverter for PathString:

TypeDescriptor.AddAttributes(typeof(PathString), new TypeConverterAttribute(typeof(PathStringConverter)));

public class PathStringConverter : TypeConverter
{
    public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
    {
        return new PathString((string) value);
    }
}

This appears to work, though it feels like this should be provided by the assembly that PathString belongs to. At least if someone else runs into this issue they can use this as a solution.

@MarkPflug
Copy link
Author

I created an issue over in HttpAbstractions to track this, I'm assuming that will be the "fix". If you guys deem this worth fixing.

@HaoK
Copy link
Member

HaoK commented May 24, 2017

Yeah PathString should be fixed since its basically a string+ primitive, binding should work for it

@Eilon
Copy link
Contributor

Eilon commented Jun 9, 2017

@HaoK - can you close and link to the PR?

@Eilon Eilon added this to the 2.0.0-preview2 milestone Jun 9, 2017
@HaoK
Copy link
Member

HaoK commented Jun 12, 2017

@HaoK HaoK closed this as completed Jun 12, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants