public static async Task <UserCredentials> AuthorizeAsync(ApplicationCredentials secret,
                                                                  string provider,
                                                                  string externalToken,
                                                                  string role,
                                                                  Config configuration)
        {
            IAuthorizationCodeFlow flow;

            switch (provider)
            {
            case "Facebook":
                flow = new FacebookAuthorizationCodeFlow(externalToken,
                                                         role,
                                                         new FlowInitializer(new ServiceConfigurationFactory(configuration),
                                                                             new TmHttpClientFactory(new[]
                {
                    new UnsuccessResponseDelegatingHandler()
                })));
                break;

            default:
                throw new ArgumentException(provider);
            }

            var credentials = new UserCredentials(new UserCredentials.Initializer(flow, secret, new ServiceConfigurationFactory(configuration)));
            await credentials.GetTokenAsync();

            return(credentials);
        }
Esempio n. 2
0
 public Initializer(IAuthorizationCodeFlow authCodeFlow,
                    ApplicationCredentials secret,
                    IServiceConfigurationFactory configurationFactory)
 {
     Secret               = secret;
     AuthCodeFlow         = authCodeFlow;
     ConfigurationFactory = configurationFactory;
 }
        public static async Task <UserCredentials> AuthorizeAsync(ApplicationCredentials secret,
                                                                  string applicationToken,
                                                                  Config configuration)
        {
            IAuthorizationCodeFlow flow =
                new ApplicationTokenAuthorizationCodeFlow(applicationToken,
                                                          new FlowInitializer(new ServiceConfigurationFactory(configuration),
                                                                              new TmHttpClientFactory(new[]
            {
                new UnsuccessResponseDelegatingHandler()
            })));
            var credentials = new UserCredentials(new UserCredentials.Initializer(flow, secret, new ServiceConfigurationFactory(configuration)));
            await credentials.GetTokenAsync();

            return(credentials);
        }
        public static async Task <UserCredentials> AuthorizeAsync()
        {
            var config = (TmAuthorizationSection)ConfigurationManager.GetSection("authorizationGroup/tmAuthorization");

            if (config?.Application != null)
            {
                var secret = new ApplicationCredentials(config.Application.ClientId, config.Application.ClientSecret);

                if (config.Token != null &&
                    config.Token.ElementInformation.IsPresent &&
                    !string.IsNullOrWhiteSpace(config.Token.Value))
                {
                    return(await AuthorizeAsync(secret, config.Token.Value, config.ApiConfigType));
                }
                if (config.Credentials != null && config.Credentials.ElementInformation.IsPresent)
                {
                    return(await AuthorizeAsync(secret, config.Credentials.UserName, config.Credentials.Password, config.ApiConfigType));
                }
            }

            return(null);
        }
Esempio n. 5
0
 public UserCredentials(Initializer initializer)
 {
     _flow     = initializer.AuthCodeFlow;
     _secret   = initializer.Secret;
     ApiConfig = initializer.ConfigurationFactory.CreateConfiguration();
 }