Example #1
0
func (psd *principalServiceDelegate) getOAuth2Token() (string, error) {
	authReq, authPtr := auth.CreateMessagePipeForAuthenticationService()
	psd.Ctx.ConnectToApplication("mojo:authentication").ConnectToService(&authReq)
	authProxy := auth.NewAuthenticationServiceProxy(authPtr, bindings.GetAsyncWaiter())

	name, errString, _ := authProxy.SelectAccount(false /*return_last_selected*/)
	if name == nil {
		return "", fmt.Errorf("Failed to select an account for user:%s", errString)
	}

	token, errString, _ := authProxy.GetOAuth2Token(*name, []string{"email"})
	if token == nil {
		return "", fmt.Errorf("Failed to obtain OAuth2 token for selected account:%s", errString)
	}
	return *token, nil
}
Example #2
0
func (pImpl *principalServiceImpl) Login() (b *vpkg.Blessing, err error) {
	authReq, authPtr := auth.CreateMessagePipeForAuthenticationService()
	pImpl.psd.Ctx.ConnectToApplication("mojo:authentication").ConnectToService(&authReq)
	authProxy := auth.NewAuthenticationServiceProxy(authPtr, bindings.GetAsyncWaiter())
	name, errString, _ := authProxy.SelectAccount(false /*return_last_selected*/)
	if name != nil {
		cert, privKey, err := newPrincipal(*name)
		if err != nil {
			return nil, err
		}
		b = &vpkg.Blessing{[]vpkg.Certificate{*cert}}
		pImpl.psd.addPrincipal(pImpl.app, &principal{b, privKey})
	} else {
		err = fmt.Errorf("Failed to authenticate user:%s", errString)
	}
	return
}