Exemplo n.º 1
0
// NormalizeSocialAssertion creates a SocialAssertion from its
// input and normalizes it.  The service name will be lowercased.
// If the service is case-insensitive, then the username will also
// be lowercased.  Colon assertions (twitter:user) will be
// transformed to the user@twitter format.  Only registered
// services are allowed.
func NormalizeSocialAssertion(s string) (keybase1.SocialAssertion, bool) {
	if strings.Count(s, ":")+strings.Count(s, "@") != 1 {
		return keybase1.SocialAssertion{}, false
	}

	var name, service string

	if strings.Contains(s, ":") {
		pieces := strings.Split(s, ":")
		service = pieces[0]
		name = pieces[1]
	} else {
		pieces := strings.Split(s, "@")
		name = pieces[0]
		service = pieces[1]
	}

	service = strings.ToLower(service)
	if !ValidSocialNetwork(service) {
		return keybase1.SocialAssertion{}, false
	}

	st := GetServiceType(service)
	name, err := st.NormalizeUsername(name)
	if err != nil {
		return keybase1.SocialAssertion{}, false
	}

	return keybase1.SocialAssertion{
		User:    name,
		Service: keybase1.SocialAssertionService(service),
	}, true
}
Exemplo n.º 2
0
// NormalizeSocialAssertion creates a SocialAssertion from its
// input and normalizes it.  The service name will be lowercased.
// If the service is case-insensitive, then the username will also
// be lowercased.  Colon assertions (twitter:user) will be
// transformed to the user@twitter format.  Only registered
// services are allowed.
func NormalizeSocialAssertion(s string) (keybase1.SocialAssertion, bool) {
	url, err := ParseAssertionURL(s, true)
	if err != nil || !url.IsRemote() {
		return keybase1.SocialAssertion{}, false
	}
	return keybase1.SocialAssertion{
		User:    url.GetValue(),
		Service: keybase1.SocialAssertionService(url.GetKey()),
	}, true
}