예제 #1
0
 private ProfileTypeRegistry(IReadOnlyList <IProfileType> allTypes, GenericProfile genericProfile, GoogleProfile googleProfile)
 {
     _genericProfile    = genericProfile;
     _googleProfile     = googleProfile;
     AllTypes           = allTypes;
     _profileTypeByName = allTypes.ToDictionary(GetProfileTypeName);
 }
예제 #2
0
        private static IProfileTypeRegistry Create()
        {
            var generic = new GenericProfile();
            var google  = new GoogleProfile();
            var all     = new List <IProfileType> {
                generic, google
            };

            all.Add(new ContactsiCloudProfile());
            all.Add(new FruuxProfile());
            all.Add(new PosteoProfile());
            all.Add(new YandexProfile());
            all.Add(new GmxCalendarProfile());
            all.Add(new SarenetProfile());
            all.Add(new LandmarksProfile());
            all.Add(new SogoProfile());
            all.Add(new CozyProfile());
            all.Add(new NextcloudProfile());
            all.Add(new MailboxOrgProfile());
            all.Add(new OpenXchangeProfile());
            all.Add(new EasyProjectProfile());
            all.Add(new WebDeProfile());
            all.Add(new SmarterMailProfile());
            all.Add(new MailDeProfile());
            all.Add(new KolabProfile());
            all.Add(new SwisscomProfile());

            return(new ProfileTypeRegistry(all, generic, google));
        }
예제 #3
0
        public async Task <GoogleProfile> GetProfile(string code)
        {
            string sessionId          = RandomStringService.GenerateAlphaNumeric(30, new Random());
            AccessTokenResponse token = await Post <AccessTokenResponse>($"https://oauth2.googleapis.com/token?code={code}&client_id={_clientId}&client_secret={_clientSecret}&redirect_uri={_config["url:ui"]}/accounts/google-auth&grant_type=authorization_code&state={sessionId}");

            AddBearerToken(token.Access_Token);
            GoogleProfile profile = await Get <GoogleProfile>($"https://openidconnect.googleapis.com/v1/userinfo?state={sessionId}&scope=email profile email");

            return(profile);
        }
예제 #4
0
        public async Task <IActionResult> GoogleAuth(string code)
        {
            if (code == null)
            {
                return(BadRequest(new { Error = "Authentication code required" }));
            }
            GoogleProfile profile = await _googleHttpService.GetProfile(code);

            return(await HandleExternalProviderProfile((LoginProvider)profile));
        }
    public async Task Check(GoogleProfile googleprofile)
    {
        var ID = googleprofile.Id;

        if (string.IsNullOrEmpty(ID))
        {
            return;
        }
        else
        {
            await Navigation.PushAsync(new Home());
        }
    }
예제 #6
0
    private void CheckLoginGoogle(GoogleProfile profile)
    {
        string user = profile.Id;

        kn.conn.Open();
        SqlDataAdapter da = new SqlDataAdapter("select * from tbluser where username='******'", kn.conn);
        DataTable      tb = new DataTable();

        da.Fill(tb);
        if (tb.Rows.Count < 1)
        {
            string     pass  = kn.mahoa(user);
            string     query = "insert into tblUser(UserName,Pass,NameUser,Email,Img) values ('" + user + "','" + pass + "','" + profile.Name + "','" + profile.Email + "','" + profile.Picture.ToString() + "')";
            SqlCommand sql   = new SqlCommand(query, kn.conn);
            sql.ExecuteNonQuery();
        }
        Session["name"]  = user;
        Session["allow"] = true;
        UpDateData(user);
        kn.conn.Close();
        Response.Redirect("Info.aspx");
    }
예제 #7
0
        private void Authenticate(object arg)
        {
            try
            {
                if (_authMode == AuthMode.Google)
                {
                    GoogleAccessToken token   = GoogleOAuth2Provider.GetAccessToken(_oAuth2Code);
                    GoogleProfile     profile = GoogleOAuth2Provider.GetUserProfile(token);

                    Program.ImapClient.Credentials = new OAuth2Credentials(profile.email, token.access_token);
                }
                else if (_authMode == AuthMode.Outlook)
                {
                    var token   = OutlookOAuth2Provider.GetAccessToken(_oAuth2Code);
                    var profile = OutlookOAuth2Provider.GetUserProfile(token.access_token);
                    Program.ImapClient.Credentials = new OAuth2Credentials(profile.emails.account, token.access_token);
                }
                else if (_authMode == AuthMode.Yahoo)
                {
                    var token = YahooOAuth2Provider.GetAccessToken(_oAuth2Code);
                    Program.ImapClient.Credentials = new OAuth2Credentials(token.xoauth_yahoo_guid, token.access_token, "ImapX");
                }

                if (Program.ImapClient.Login())
                {
                    Invoke(new SuccessDelegate(OnAuthenticateSuccessful));
                }
                else
                {
                    Invoke(new FailedDelegate(OnAuthenticateFailed));
                }
            }
            catch (Exception ex)
            {
                Invoke(new FailedDelegate(OnAuthenticateFailed), new[] { ex });
            }
        }
 public UyeModel Post(GoogleProfile value)
 {
     return(islem.GoogleGirisi(value));
 }
예제 #9
0
    protected void GetGmailLogInDetails()
    {
        string ip    = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
        string code  = Request.QueryString["code"];
        var    token = "https://www.googleapis.com/oauth2/v3/token?code=" + code
                       + "&redirect_uri=" + GoogleRedirectUrl + "&client_id=" + GoogleClientId
                       + "&scope=&client_secret=" + GoogleClientSecret
                       + "&grant_type=authorization_code";

        HttpClient client  = new HttpClient();
        var        request = WebRequest.Create(token);

        request.Headers.Add("Authorization", "");
        request.Method = "POST";
        try
        {
            var requestStream = request.GetRequestStream();
            var responses     = request.GetResponse();
            using (var responseStream = responses.GetResponseStream())
            {
                var reader       = new StreamReader(responseStream);
                var responseText = reader.ReadToEnd();

                AccessTok m = JsonConvert.DeserializeObject <AccessTok>(responseText);
                Acesss_token = m.Access_Token;
            }
            Response.Close();
        }
        catch (WebException ex)
        {
            if (Session["ExternalUserId"] != null)
            {
                Response.Redirect("Home.aspx");
            }
            ex.Message.ToString();
        }

        var GplusUserInfo = "https://www.googleapis.com/plus/v1/people/me?access_token=" + Acesss_token;

        try
        {
            if (GplusUserInfo != string.Empty)
            {
                HttpWebRequest requests = (HttpWebRequest)WebRequest.Create(GplusUserInfo);
                requests.Method        = "GET";
                requests.ContentLength = 0;
                HttpWebResponse response = (HttpWebResponse)requests.GetResponse();

                if (response.StatusCode.ToString().ToLower() == "ok")
                {
                    string contentType = response.ContentType;
                    Stream content     = response.GetResponseStream();
                    if (content != null)
                    {
                        StreamReader contentReader = new StreamReader(content);
                        Response.ContentType = contentType;
                        var           responseText = contentReader.ReadToEnd();
                        GoogleProfile Gplus        = JsonConvert.DeserializeObject <GoogleProfile>(responseText);
                        string        gender       = Gplus.gender;
                        string        Email        = Gplus.Emails.Find(email => email.Type == "account").Value;

                        string   name      = Gplus.displayName;
                        string[] words     = name.Split(' ');
                        string   FirstName = words[0];
                        string   Lastname  = words[1];

                        DA_Registrationdetails objRegistrationDB = new DA_Registrationdetails();
                        DO_Registrationdetails objRegistration   = new DO_Registrationdetails();
                        DataTable dt = new DataTable();
                        objLogin.Username = Email;

                        dt = objLoginDB.GetDataSet(objLogin, DA_SKORKEL.DA_Login.Login_1.GmailFBLogin);
                        if (dt.Rows.Count == 0)
                        {
                            string password = GeneratePassword();
                            objRegistration.FirstName  = FirstName;
                            objRegistration.LastName   = Lastname;
                            objRegistration.UserName   = Email;
                            objRegistration.Password   = password;
                            objRegistration.UserTypeId = 1;
                            if (gender == "male")
                            {
                                objRegistration.Sex = "M";
                            }
                            else
                            {
                                objRegistration.Sex = "F";
                            }
                            objRegistrationDB.AddEditDel_RegistrationDetails(objRegistration, DA_Registrationdetails.RegistrationDetails.Add);

                            UserSession.UserInfo UInfo = new UserSession.UserInfo();
                            UInfo.UserName = Convert.ToString(objRegistration.UserName);
                            UInfo.UserID   = Convert.ToInt64(objRegistration.RegOutId);
                            int TypeId = Convert.ToInt32(objRegistration.UserTypeId);
                            Session.Add("UserTypeId", TypeId);
                            Session.Add("UInfo", UInfo);
                            Session.Add("LoginName", name);
                            Session.Add("ExternalUserId", Convert.ToString(objRegistration.RegOutId));

                            if (ISAPIURLACCESSED == "1")
                            {
                                String UserURL = APIURL + "registerUser.action?" +
                                                 "uid=" + objRegistration.RegOutId +
                                                 "&userId=" + objRegistration.UserName +
                                                 "&password="******"&firstName=" + objRegistration.FirstName +
                                                 "&lastName=" + objRegistration.LastName +
                                                 "&userType=STUDENT" +
                                                 "&userContextIds=" + null +
                                                 "&friendUserIds=" + null +
                                                 "&lawRelated=" + null;
                                try
                                {
                                    HttpWebRequest myRequest1 = (HttpWebRequest)WebRequest.Create(UserURL);
                                    myRequest1.Method = "GET";
                                    WebResponse myResponse1 = myRequest1.GetResponse();

                                    StreamReader sr     = new StreamReader(myResponse1.GetResponseStream(), System.Text.Encoding.UTF8);
                                    String       result = sr.ReadToEnd();

                                    objAPILogDO.strURL      = UserURL;
                                    objAPILogDO.strAPIType  = "Student";
                                    objAPILogDO.strResponse = result;

                                    if (ip == null)
                                    {
                                        objAPILogDO.strIPAddress = Request.ServerVariables["REMOTE_ADDR"];
                                    }
                                    objAPILogDA.AddEditDel_Scrl_APILogDetailsTbl(objAPILogDO, DA_Scrl_APILogDetailsTbl.Scrl_APILogDetailsTbl.Insert);
                                }
                                catch (Exception ex)
                                {
                                    ex.Message.ToString();
                                }
                            }

                            activate();
                        }
                        else
                        {
                            UserSession.UserInfo UInfo = new UserSession.UserInfo();
                            string LoginName           = Convert.ToString(dt.Rows[0]["LoginName"]);
                            UInfo.UserName = Convert.ToString(dt.Rows[0]["vchrUserName"]);
                            UInfo.UserID   = Convert.ToInt64(dt.Rows[0]["intRegistrationId"]);
                            int TypeId = Convert.ToInt32(dt.Rows[0]["intUserTypeID"]);
                            //vchrPassword
                            Session.Add("UserTypeId", TypeId);
                            Session.Add("UInfo", UInfo);
                            Session.Add("LoginName", LoginName);
                            Session.Add("ExternalUserId", Convert.ToString(dt.Rows[0]["intRegistrationId"]));
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            ex.Message.ToString();
        }
        finally
        {
            if (Session["ExternalUserId"] != null)
            {
                Response.Redirect("Home.aspx");
            }
        }
    }
예제 #10
0
 private void SetPageContent(GoogleProfile googleProfile)
 {
     Content = new StackLayout
     {
         Orientation = StackOrientation.Vertical,
         Padding     = new Thickness(8, 30),
         Children    =
         {
             new Label
             {
                 Text      = googleProfile.DisplayName,
                 TextColor = Color.Black,
                 FontSize  = 22,
             },
             new Label
             {
                 Text      = googleProfile.Id,
                 TextColor = Color.Black,
                 FontSize  = 22,
             },
             new Label
             {
                 Text      = googleProfile.Verified.ToString(),
                 TextColor = Color.Black,
                 FontSize  = 22,
             },
             new Label
             {
                 Text      = googleProfile.Gender,
                 TextColor = Color.Black,
                 FontSize  = 22,
             },
             new Label
             {
                 Text      = googleProfile.Tagline,
                 TextColor = Color.Black,
                 FontSize  = 22,
             },
             new Label
             {
                 Text      = googleProfile.CircledByCount.ToString(),
                 TextColor = Color.Black,
                 FontSize  = 22,
             },
             new Label
             {
                 Text      = googleProfile.Occupation,
                 TextColor = Color.Black,
                 FontSize  = 22,
             },
             new Xamarin.Forms.Image
             {
                 Source        = googleProfile.Image.Url,
                 HeightRequest = 100
             },
             new Xamarin.Forms.Image
             {
                 Source        = googleProfile.Cover.CoverPhoto.Url,
                 HeightRequest = 100
             },
         }
     };
 }
예제 #11
0
 public async Task SetGoogleUserProfileAsync(string accessToken)
 {
     GoogleProfile = await _googleServices.GetGoogleUserProfileAsync(accessToken);
 }