Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

injectable login providers + SRP #520

Merged
merged 4 commits into from
Jun 24, 2022

Conversation

Jin-K
Copy link
Contributor

@Jin-K Jin-K commented Jun 21, 2022

  • Since LoginProvider & BaseLoginProvider are exported from the lib, as consumers we can implement our own login providers.
    That's good but we seem forced to create our login provider instances directly when we provide a value for SocialAuthServiceConfig, and we have no easy way to inject other services in our custom login providers.

    This PR should make something like this possible

    @Injectable({ providedIn: 'root' })
    export class MyCustomLoginProvider extends BaseLoginProvider {
      public static readonly PROVIDER_ID = 'CUSTOM' as const;
    
      constructor(/* infinite list of dependencies*/) {}
    }
    
    ...
    
    @NgModule({
      declarations: [AppComponent, NavbarComponent, DemoComponent],
      imports: [BrowserModule, FormsModule, SocialLoginModule],
      providers: [
        {
          provide: 'SocialAuthServiceConfig',
          useValue: {
            autoLogin: true,
            providers: [
              {
                id: MyCustomLoginProvider.PROVIDER_ID,
                provider: MyCustomLoginProvider,
              },
            ],
          } as SocialAuthServiceConfig,
        },
      ],

    MyCustomLoginProvider would then be a real angular provider.

  • A change was made also on getLoginStatus(refreshToken?: boolean): Promise<SocialUser> signature, it was splitted into getLoginStatus(): Promise<SocialUser> & refreshToken?(): Promise<SocialUser | null>.
    The refreshToken?: boolean parameter was only used by GoogleLoginProvider, and passing true to it was doing something really different of passing false.

    With that new optional refreshToken() method that providers can implement, we just need to check for the presence of a refreshToken function in SocialAuthService.refreshAuthToken()

  • signIn() method abstract again in BaseLoginProvider, GoogleLoginProvider implements it again but rejects with a message saying it is no longer supported, with a link to Google doc.

@Heatmanofurioso Heatmanofurioso merged commit 65bf76e into abacritt:master Jun 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants