Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Daniel Rogers 139 posts 717 karma points
    Mar 06, 2024 @ 14:14
    Daniel Rogers
    0

    Access CustomService from IUmbracoBuilder Composer

    I'm trying to implement Google oAuth example witch is compiling but I want to take it one step further and not have client ID and secret hardcoded.

    I have a service that gets the content from a settings page and are initializing it inside the builder.

    public class RegisterSiteServiceComposer : IComposer
    {
        public void Compose(IUmbracoBuilder builder)
        {
            builder.Services.AddScoped<IIBDContentService, IBDContentService>();
            builder.AddGoogleAuthentication();
        }
    }
    

    But how do I inject that into so it can be used from the AddGoogleAuthentication().

    .........
    // The scheme must be set with this method to work for the back office
    var schemeName =     backOfficeAuthenticationBuilder.SchemeForBackOffice(GoogleBackOfficeExternalLoginProviderOptions.SchemeName);
    
    OAuthSettings oAuth = _contentService.GetOAuthSettings("Google", "user");
    ................
    

    Have used this https://docs.umbraco.com/umbraco-cms/tutorials/add-google-authentication for implementing all the code.

    Is this possible and if so how.

    Normally I would do something like this:

        public partial class SomeController : UmbracoAuthorizedJsonController {
            private readonly IBDContentService _contentService;
    
            public SomeController (IBDContentService contentService)
            {
                _contentService= contentService;
            }
    
            public void someRoutine() {
                ........
                OAuthSettings oAuth = _contentService.GetOAuthSettings("Google", "user");
               .......
           }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft